/**
 * EH 复制PC端的查询类，标准版2024-06-06
 * 参照：Nur.NIS.Service.OrderExcute.QueryOrder
 * 原则：能省则省，这个类只是为了提供医嘱id
 */

Class Nur.MNISV3.Service.QueryOrder Extends %RegisteredObject [ Not ProcedureBlock ]
{

/// Description:    获取前端选中单据下医嘱信息并判断其他单据下是否有医嘱
/// Input:          episodeIDStr：就诊号串(以^分割)，currentSheetCode：前端选中单据Code     
///                 groupID：安全组ID
///                 startDate：开始日期，startTime：开始时间
///                 endDate：结束日期，endTime：结束时间
///                 hospID：医院ID，wardID：病区ID
///                 locID：科室ID，doctorOrderFlag：医生医嘱为true、护士医嘱为false
///                 createOrderFlag：要求执行时间为false、开医嘱时间为true，orderType：医嘱类型默认为A
///                 excutedOrderFlag：筛选已执行为true、筛选未执行为false，ifPrint：筛选已打印为true、筛选未打印为false
///                 longOrderFlag：筛选长期医嘱为true，tempOrderFlag：筛选临时医嘱为true
///                 newCreateFlag：筛选今日新开医嘱为true，newDisconFlag：筛选今日新停医嘱为true
/// Return:       
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).GetOrders("1157^147^357^178","DefaultSee","132","2024-04-16","00:00","2024-04-16","23:59","2","3","8","true","false","A","false","","false","false","false","false","")
ClassMethod GetOrders(PDAParam, episodeIDStr, currentSheetCode, groupID, startDate, startTime, endDate, endTime, hospID, wardID, locID, doctorOrderFlag, createOrderFlag, orderType = "A", excutedOrderFlag, ifPrint, longOrderFlag = "false", tempOrderFlag = "false", newCreateFlag = "false", newDisconFlag = "false", confirmFlag = "") As %ArrayOfDataTypes
{
    n (PDAParam, episodeIDStr, currentSheetCode, groupID, startDate, startTime, endDate, endTime, hospID, wardID, locID, doctorOrderFlag, createOrderFlag, orderType , excutedOrderFlag, ifPrint, longOrderFlag , tempOrderFlag , newCreateFlag, newDisconFlag, confirmFlag, %session)
    s ^PDAtemp("GetOrders",1,episodeIDStr)=$lb(episodeIDStr, currentSheetCode, groupID, startDate, startTime, endDate, endTime, hospID, wardID, locID, doctorOrderFlag, createOrderFlag, orderType , excutedOrderFlag, ifPrint, longOrderFlag , tempOrderFlag , newCreateFlag, newDisconFlag, confirmFlag)
    s ^PDAtemp("GetOrders","PDAParam")=PDAParam.PDAStart_"-"_PDAParam.PDALimit_"-"_PDAParam.PDAScreenings
    // 记录其他单据是否有医嘱
    s orderObject=##class(%ArrayOfDataTypes).%New()

    s startDate=##class(websys.Conversions).DateHtmlToLogical(startDate)
    s endDate=##class(websys.Conversions).DateHtmlToLogical(endDate)
    s startTime=$zth(startTime)
    s endTime=$zth(endTime)+59
    
    // 获取出入转护士执行配置
    s transSetting=##class(Nur.NIS.Service.OrderExcute.QueryOrder).GetTransSetting(hospID)
    s dischargeSetting=$p($g(transSetting),"^",1)
    
    //获取医嘱颜色配置
    s colorsSetting="" ;;;..GetColorsSetting(hospID,wardID,currentSheetCode)
    
    // 护士医嘱、医生医嘱
    s ctcptType=""
    if ($g(doctorOrderFlag)="true"){
        s ctcptType="DOCTOR"
    }elseif ($g(doctorOrderFlag)="false"){
        s ctcptType="NURSE"
    }
    i locID'="" s locType=$p(^CTLOC(locID),"^",13)
    
    // 获取当前单据护士执行列设置
    s columns="" ;;;..GetSheetColumns(currentSheetCode,hospID)
    
    //获取当前单据类型
    s currentSheetType=..GetSheetTypeBySheetCode(currentSheetCode,hospID)
    
    // 获取非当前单据外的其他单据的Code及护士执行筛选条件
    s sheetsSetting="" ;;;..GetSheetsSetting(groupID,locID,hospID,currentSheetCode)
    ;;;i (newCreateFlag="true")||(newDisconFlag="true") {
        ;;;s createOrderFlag="false"
    ;;;}
 
    
    // 保存查询参数的对象
    s queryArgument=##class(OrderParam).%New()
    d queryArgument.groupIDSet(groupID)
    d queryArgument.hospIDSet(hospID)
    d queryArgument.wardIDSet(wardID)
    d queryArgument.locIDSet(locID)
    d queryArgument.createOrderFlagSet(createOrderFlag)
    d queryArgument.orderTypeSet(orderType)
    d queryArgument.excutedOrderFlagSet(excutedOrderFlag)
    d queryArgument.ifPrintSet(ifPrint)
    d queryArgument.longOrderFlagSet(longOrderFlag)
    d queryArgument.tempOrderFlagSet(tempOrderFlag)
    d queryArgument.newCreateFlagSet(newCreateFlag)
    d queryArgument.newDisconFlagSet(newDisconFlag)
    d queryArgument.ctcptTypeSet(ctcptType)
    d queryArgument.locTypeSet(locType)
    d queryArgument.startDateSet(startDate)
    d queryArgument.startTimeSet(startTime)
    d queryArgument.endDateSet(endDate)
    d queryArgument.endTimeSet(endTime)
    d queryArgument.confirmFlagSet(confirmFlag)
    d queryArgument.CopyFrom(PDAParam)
    //i currentSheetCode="BGYZD" {
    i currentSheetType="BGYZD" {
        s createOrderFlag="true"
    }
    //  按照下医嘱日期查询分两种情况——pjf
    //  1.查询执行记录 查询当天有执行记录且下医嘱日期在查询范围内的医嘱
    //  2.查询医嘱 查询下医嘱日期在查询范围内的医嘱
    i (createOrderFlag="true") {
        s startCreateDate=startDate,endCreateDate=endDate
        s startCreateTime=startTime,endCreateTime=endTime
        s startDate=+$h,endDate=+$h
        s startTime=0,endTime=86340
        //i currentSheetCode="BGYZD" {
        i currentSheetType="BGYZD" {
            s startCreateDate=+$h,endCreateDate=+$h
            s startCreateTime=0,endCreateTime=86399
        }
        d queryArgument.startCreateDateSet(startCreateDate)
        d queryArgument.startCreateTimeSet(startCreateTime)
        d queryArgument.endCreateDateSet(endCreateDate)
        d queryArgument.endCreateTimeSet(endCreateTime)
    }
    s ifDeliveryRoom=##class(Nur.NIS.Service.OrderExcute.QueryOrder).ifDeliveryRoom(locID)
    s patNum=$l(episodeIDStr,"^")
    // 前端选中单据医嘱数据
    k ordersData
    // 记录同处置状态、同标本号合管医嘱
    k labData
    // 记录同检查部位ID，同医嘱ID合并医嘱
    k examData
    
    f i=1:1:patNum
    {
        s episodeID=$p(episodeIDStr,"^",i)
        continue:episodeID=""
        /*s deliveryRommID=##class(Nur.IP.Delivery).getDeliveryRoomID(episodeID)
        s ifDeliveryRoom=0
        //判断当前是否是产房(1:是产房、0:不是产房)
        s:deliveryRommID=locID ifDeliveryRoom=1*/
        
        s admVisitStatus=$p(^PAADM(episodeID),"^",20)   
        s billStatus=##class(web.DHCDischargeHistory).GetCurrentDischargeStatus(episodeID)  
        // 根据配置判断是否过滤出院患者
        if (dischargeSetting'="Y")&&(admVisitStatus="D")&&(billStatus'="B"){
            ;;;d orderObject.SetAt("患者"_##class(Nur.NIS.Service.Base.Patient).GetName(episodeID)_"已出院,没有医嘱查询权限！","alertMsg")
            continue
        }
        
        
        ;;;i currentSheetCode="DefaultSee" {
        i currentSheetType="DefaultSee" {
            // 如果前端选中单据为需处理，查询需处理下所有医嘱数据
            ;;;d ..GetDefaultSeeOrders(episodeID, i, "DefaultSee", queryArgument, ifDeliveryRoom, admVisitStatus, columns, "1", .orderObject, .ordersData, .labData,colorsSetting)
            d ..GetDefaultSeeOrders(episodeID, i, currentSheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns, "1", .orderObject, .ordersData, .labData,colorsSetting)
            // 查询其他单据下是否存在医嘱，有一条则返回true并跳出
            ;;;i sheetsSetting.Count()>0 {
                ;;;d ..GetOtherSheetOrders(episodeID, i, "DefaultSee", queryArgument, ifDeliveryRoom, admVisitStatus, columns, sheetsSetting, "0", .orderObject, .ordersData, .labData,.examData,colorsSetting)
            ;;;}
            // 查询变化医嘱单下是否存在医嘱,有一条则返回true
            ;;;i orderObject.GetAt("BGYZD")'="true" {
                 ;;;d ..GetBHYZDOrders(episodeID, i, "BGYZD", queryArgument, ifDeliveryRoom, admVisitStatus, columns, "0", .orderObject, .ordersData, .labData,colorsSetting)
            ;;;}
        }else{
            ;;;if currentSheetCode="BGYZD" {
            if currentSheetType="BGYZD" {
                // 如果前端选中单据为变化医嘱单，查询变化医嘱单下所有医嘱数据
                ;;;d ..GetBHYZDOrders(episodeID, i, "BGYZD", queryArgument, ifDeliveryRoom, admVisitStatus, columns, "1", .orderObject, .ordersData, .labData,colorsSetting)
                d ..GetBHYZDOrders(episodeID, i, currentSheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns, "1", .orderObject, .ordersData, .labData,colorsSetting)
                // 如果前端选中单据不是需处理，查询当前单据下所有医嘱数据，并查询其他单据下是否存在医嘱，有一条则返回true
                ;;;i sheetsSetting.Count()>0 {
                    ;;;d ..GetOtherSheetOrders(episodeID, i, "BGYZD", queryArgument, ifDeliveryRoom, admVisitStatus, columns,sheetsSetting, "0", .orderObject, .ordersData, .labData,.examData,colorsSetting)
                ;;;}
            }else{
                // 如果前端选中单据不是需处理，查询当前单据下所有医嘱数据，并查询其他单据下是否存在医嘱，有一条则返回true
                d ..GetOtherSheetOrders(episodeID, i, currentSheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns,sheetsSetting, "1", .orderObject, .ordersData, .labData,.examData,colorsSetting)
                ;;;i orderObject.GetAt("BGYZD")'="true" {
                    ;;;d ..GetBHYZDOrders(episodeID, i, "BGYZD", queryArgument, ifDeliveryRoom, admVisitStatus, columns, "0", .orderObject, .ordersData, .labData,colorsSetting)
                ;;;}
            }
            // 查询需处理是否存在医嘱，有一条则返回true并跳出
            ;;;i orderObject.GetAt("DefaultSee")'="true" {
                ;;;d ..GetDefaultSeeOrders(episodeID, i, "DefaultSee", queryArgument, ifDeliveryRoom, admVisitStatus, columns, "0", .orderObject, .ordersData, .labData,colorsSetting)
            ;;;}
        }
        ;;;s j=0
        ;;;while j<sheetsSetting.Count() {
            ;;;s j=j+1
            ;;;#dim tempSheetSetting As %ArrayOfDataTypes
            ;;;s tempSheetSetting=sheetsSetting.GetAt(j)
            ;;;continue:$IsObject(tempSheetSetting)=0
            ;;;s tempSheetCode=tempSheetSetting.GetAt("Code")
            ;;;s tempSheetType=tempSheetSetting.GetAt("sheetType")
            //是否当前单据
            ;;;i tempSheetCode=currentSheetCode s isCurrentSheet=1
            ;;;e  s isCurrentSheet=0
            ;;;if (tempSheetType="DefaultSee"){
                ;;;continue:..filterSearch(isCurrentSheet,tempSheetCode,orderObject)
                ;;;d ..GetDefaultSeeOrders(episodeID, i, tempSheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns, isCurrentSheet, .orderObject, .ordersData, .labData,colorsSetting)
            ;;;}elseif(tempSheetType="BGYZD"){
                ;;;continue:..filterSearch(isCurrentSheet,tempSheetCode,orderObject)
                ;;;d ..GetBHYZDOrders(episodeID, i, tempSheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns, isCurrentSheet, .orderObject, .ordersData, .labData,colorsSetting)
            ;;;}else{
                ;;;s otherSheetCode=tempSheetCode
            ;;;}
        ;;;}
        //如果前端选中单据类型非其它,查询其他单据下是否存在医嘱
        //如果前端选中单据类型为其它,查询当前单据医嘱数据并返回非当前其它单据是否存在医嘱
        ;;;if (currentSheetType="DefaultSee")||(currentSheetType="BGYZD") s isCurrentSheet=0
        ;;;else  s isCurrentSheet=1,otherSheetCode=currentSheetCode
        ;;;if ($g(otherSheetCode)'="") d ..GetOtherSheetOrders(episodeID, i, otherSheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns, sheetsSetting, isCurrentSheet, .orderObject, .ordersData, .labData,.examData,colorsSetting)
    }
    s orderList=##class(%ListOfDataTypes).%New()
    s patIndex=""
    for
    {
        s patIndex=$o(ordersData(patIndex))
        q:patIndex=""
        s dateTimeSort=""
        for
        {
            s dateTimeSort=$o(ordersData(patIndex,dateTimeSort))
            q:dateTimeSort=""
            s IDSort=""
            for
            {
                s IDSort=$o(ordersData(patIndex,dateTimeSort,IDSort))
                q:IDSort=""
                s IDSortSub=""
                for
                {
                    s IDSortSub=$o(ordersData(patIndex,dateTimeSort,IDSort,IDSortSub))
                    q:IDSortSub=""
                    #dim orderInfo As %ArrayOfDataTypes
                    s orderInfo=ordersData(patIndex,dateTimeSort,IDSort,IDSortSub)
                    d orderList.Insert(orderInfo)               
                }
            }
        }
    }
    d orderObject.SetAt(orderList,"orders")
    //返回obj对象,不进行json序列化
    if PDAParam.PDAGetOrder=0 q orderObject
    q ##class(Nur.JSON).Encode(orderObject)
}

ClassMethod filterSearch(isCurrentSheet, sheetCode, orderObject As %ArrayOfDataTypes)
{
    i (isCurrentSheet=0)&&(orderObject.GetAt(sheetCode)) {
        q 1
    }
    q 0
}

/// Description:    获取单个患者所有需处理医嘱
/// Input:          episodeID：当前患者就诊号，sheetCode：单据Code(DefaultSee)
///                 queryArgument：查询参数对象，ifDeliveryRoom：当前是否是产房(1:是产房、0:不是产房)
///                 admVisitStatus：患者状态，columns：需处理的列数组
///                 isCurrentSheet：当前单据是否为前端选中单据(1:是、0:不是)，orderObject：记录其他单据是否有医嘱的对象
///                 ordersData：前端选中单据医嘱数据，labData：记录同处置状态、同标本号合管医嘱
/// Return:       
/// Other:  
ClassMethod GetDefaultSeeOrders(episodeID, patIndex, sheetCode, queryArgument As OrderParam, ifDeliveryRoom, admVisitStatus, columns As %ListOfDataTypes, isCurrentSheet, orderObject As %ArrayOfDataTypes, ordersData, labData, colorsSetting As %ListOfDataTypes) As %String
{
    n (episodeID, patIndex, sheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns, isCurrentSheet, orderObject, ordersData, labData, colorsSetting,%session)

    s excutedOrderFlag=queryArgument.excutedOrderFlagGet()
    s newDisconFlag=queryArgument.newDisconFlagGet()
    s newCreateFlag=queryArgument.newCreateFlagGet()
    s startDate=queryArgument.startDateGet()
    s endDate=queryArgument.endDateGet()
    s startTime=queryArgument.startTimeGet()
    s endTime=queryArgument.endTimeGet()
    s createOrderFlag=queryArgument.createOrderFlagGet()
    s oeordID=$o(^OEORD(0,"Adm",episodeID,0)) 
    q:oeordID="" 0
    s hospID=queryArgument.hospIDGet()
    ;;;q:..filterSearch(isCurrentSheet,sheetCode,orderObject) 0
    // 获取当前单据的过滤条件
    s currentSheetSetting=..GetSheetSetting(sheetCode, hospID)
    if (excutedOrderFlag="false")||(excutedOrderFlag="") {
        // 获取停止医嘱状态
        s stopSateDr=$O(^OEC("OSTAT",0,"Code","D",""))
        q:stopSateDr="" 0
        // 获取撤销医嘱状态
        s cancelSateDr=$O(^OEC("OSTAT",0,"Code","C",""))
        
        // 需处理下未处理医嘱
        s oeoriSub=0
        for
        {
            // SeeType为U的医嘱
            s oeoriSub=$O(^OEORDi(0,"SeeType","U",oeordID,oeoriSub))
            q:oeoriSub=""
            s ordStatID=$p($g(^OEORD(oeordID,"I",oeoriSub,1)),"^",13)
            
            // 今日新停
            i (newDisconFlag="true")&&(newCreateFlag="false") {
                continue:ordStatID'=stopSateDr
            }
            // 过滤子医嘱(先判断主医嘱是否满足过滤条件)
            s ordSeqID=$p($g(^OEORD(oeordID,"I",oeoriSub,11)),"^",39)
            continue:ordSeqID'=""
            d ..GetDefaultSeeOrder(episodeID, patIndex, oeordID, oeoriSub, sheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns, currentSheetSetting, isCurrentSheet, .orderObject, .ordersData, .labData,colorsSetting)
            return:(queryArgument.PDAAtEnd=1)
        }
        ;;;q:..filterSearch(isCurrentSheet,sheetCode,orderObject) 0   
        // 停止需处理医嘱且SeeType不为U的医嘱(停止医嘱不会修改SeeType状态，可能存在SeeType为U或者为A的停止需处理医嘱)
        s ordCatDr=""
        for
        {
            s ordCatDr=$O(^OEORDi(0,"StatStDtTm1",oeordID,ordCatDr)) 
            q:ordCatDr=""
            s stateDr=""
            for
            {
                s stateDr=$o(^OEORDi(0,"StatStDtTm1",oeordID,ordCatDr,stateDr))
                q:stateDr=""
                continue:(stateDr'=stopSateDr)&&(stateDr'=cancelSateDr)
                s stDate=""
                for
                {
                    s stDate=$O(^OEORDi(0,"StatStDtTm1",oeordID,ordCatDr,stateDr,stDate)) 
                    q:stDate=""
                    s stTime=""
                    for
                    {
                        s stTime=$O(^OEORDi(0,"StatStDtTm1",oeordID,ordCatDr,stateDr,stDate,stTime)) 
                        q:stTime=""
                        s oeoriSub=0 
                        for
                        {
                            s oeoriSub=$O(^OEORDi(0,"StatStDtTm1",oeordID,ordCatDr,stateDr,stDate,stTime,oeoriSub)) 
                            i ("10012545||279")=(oeordID_"||"_oeoriSub) b
                            q:oeoriSub=""
                            s seeOrdType=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",7)
                            // 过滤SeeType为U的医嘱
                            continue:seeOrdType="U"
                            // 过滤子医嘱
                            s ordSeqID=$p($g(^OEORD(oeordID,"I",oeoriSub,11)),"^",39)
                            continue:ordSeqID'=""
                            if (createOrderFlag="false") {
                                s seeDate=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",5)
                                s seeTime=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",6)
                                // 停医嘱日期时间
                                s stopDate=$p($g(^OEORD(oeordID,"I",oeoriSub,3)),"^",34)
                                s stopTime=$p($g(^OEORD(oeordID,"I",oeoriSub,2)),"^",15)
                                i stopDate'="" {
                                    s seeDate=stopDate
                                    s seeTime=stopTime
                                }
                                s stopSeeDate=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",2)
                                s stopSeeTime=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",3)
                                // 如果为停止已处理医嘱，则按停止处理时间查询
                                i stopSeeDate'="" {
                                    s seeDate=stopSeeDate
                                    s seeTime=stopSeeTime
                                }
                                continue:(seeDate<startDate)||(seeDate>endDate)
                                continue:(seeDate=startDate)&&(seeTime<startTime)
                                continue:(seeDate=endDate)&&(seeTime>endTime)
                            }
                            d ..GetDefaultSeeOrder(episodeID, patIndex, oeordID, oeoriSub, sheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns, currentSheetSetting, isCurrentSheet, .orderObject, .ordersData, .labData,colorsSetting)
                            return:(queryArgument.PDAAtEnd=1)
                        }  
                    }
                }   
            }
        }
        ;;;q:..filterSearch(isCurrentSheet,sheetCode,orderObject) 0
        //存在已处理但预停的医嘱,按照未处理显示
        s stDate=""
        for {
            s stDate=$o(^OEORDi(0,"StDt",stDate)) q:stDate=""
            s oeoriSub=""
            for {
                s oeoriSub=$o(^OEORDi(0,"StDt",stDate,oeordID,oeoriSub)) q:oeoriSub=""
                s ordStatID=$P($G(^OEORD(oeordID,"I",oeoriSub,1)),"^",13)
                s ordStatCode=$p(^OEC("OSTAT",ordStatID),"^",1)
                continue:(ordStatCode'="V")&&(ordStatCode'="E")
                s stopDate= $p($g(^OEORD(oeordID,"I",oeoriSub,9)),"^",9)
                continue:stopDate=""
                s stopSeeDate=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",2)
                continue:stopSeeDate'=""
                // 过滤子医嘱
                s ordSeqID=$p($g(^OEORD(oeordID,"I",oeoriSub,11)),"^",39)
                continue:ordSeqID'=""
                d ..GetDefaultSeeOrder(episodeID, patIndex, oeordID, oeoriSub, sheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns, currentSheetSetting, isCurrentSheet, .orderObject, .ordersData, .labData,colorsSetting)
                return:(queryArgument.PDAAtEnd=1)
            }
        }
    }
    if (excutedOrderFlag="true")||(excutedOrderFlag=""){
        ;;;q:..filterSearch(isCurrentSheet,sheetCode,orderObject) 0     
        s oeoriSub=0
        for
        {
            s oeoriSub=$o(^OEORD(oeordID,"I",oeoriSub))
            q:oeoriSub=""
            s seeOrdType=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",7)
            continue:seeOrdType="U"
            // 过滤子医嘱
            s ordSeqID=$p($g(^OEORD(oeordID,"I",oeoriSub,11)),"^",39)
            continue:ordSeqID'=""
            // 处理日期时间
            i (createOrderFlag="false") {
                // 获取处理医嘱日期时间
                s seeDate=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",5)
                s seeTime=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",6)
                // 停医嘱日期时间
                s stopDate=$p($g(^OEORD(oeordID,"I",oeoriSub,3)),"^",34)
                s stopTime=$p($g(^OEORD(oeordID,"I",oeoriSub,2)),"^",15)
                i stopDate'="" {
                    s seeDate=stopDate
                    s seeTime=stopTime
                }
                s stopSeeDate=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",2)
                s stopSeeTime=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",3)
                // 如果为停止已处理医嘱，则按停止处理时间查询
                i stopSeeDate'="" {
                    s seeDate=stopSeeDate
                    s seeTime=stopSeeTime
                }
                continue:(seeDate<startDate)||(seeDate>endDate)
                continue:(seeDate=startDate)&&(seeTime<startTime)
                continue:(seeDate=endDate)&&(seeTime>endTime)
            }
            d ..GetDefaultSeeOrder(episodeID, patIndex, oeordID, oeoriSub, sheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns, currentSheetSetting, isCurrentSheet, .orderObject, .ordersData, .labData,colorsSetting)
            return:(queryArgument.PDAAtEnd=1)
        }
        
    }
    q 0
}

/// Description:    获取单条需处理医嘱数据
/// Input:          episodeID：当前患者就诊号，oeordID：医嘱ID
///                 oeoriSub：医嘱ID，sheetCode：单据Code(DefaultSee)
///                 queryArgument：查询参数对象，ifDeliveryRoom：当前是否是产房(1:是产房、0:不是产房)
///                 admVisitStatus：患者状态，columns：需处理的列数组
///                 isCurrentSheet：当前单据是否为前端选中单据(1:是、0:不是)，orderObject：记录其他单据是否有医嘱的对象
///                 ordersData：前端选中单据医嘱数据，labData：记录同处置状态、同标本号合管医嘱      
/// Return:       
/// Other:
ClassMethod GetDefaultSeeOrder(episodeID, patIndex, oeordID, oeoriSub, sheetCode, queryArgument As OrderParam, ifDeliveryRoom, admVisitStatus, columns As %ListOfDataTypes, currentSheetSetting As %ArrayOfDataTypes, isCurrentSheet, orderObject As %ArrayOfDataTypes, ordersData, labData, colorsSetting As %ListOfDataTypes)
{
    n (episodeID, patIndex, oeordID, oeoriSub, sheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns, currentSheetSetting, isCurrentSheet, orderObject, ordersData, labData, %session,colorsSetting)
    ;;;q:..filterSearch(isCurrentSheet,sheetCode,orderObject) 0
    // 过滤医嘱状态为空的医嘱
    ;i oeoriSub = 162 b
    s stopSateDr=$O(^OEC("OSTAT",0,"Code","D",""))
    s ordStatID=$p($g(^OEORD(oeordID,"I",oeoriSub,1)),"^",13)
    q:ordStatID="" 0
    
    // 确费标志
    s confirmFlag=queryArgument.confirmFlagGet()
    s conFeeUserDr=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",9) //确费过滤
    q:(conFeeUserDr'="")&&(confirmFlag="false") 0
    q:(conFeeUserDr="")&&(confirmFlag="true") 0
    
    // 过滤绑定需屏蔽医嘱
    s MethodParam=$g(^oddCOM("Nur.Interface.OutSide.Order","m","IsBindShieldOrder",60))
    i $lg($lg(MethodParam,1),1)="sheetCode" {
         s isBindShieldOrder=##Class(Nur.Interface.OutSide.Order).IsBindShieldOrder(sheetCode,oeordID_"||"_oeoriSub)
    }else {
         s isBindShieldOrder=##Class(Nur.Interface.OutSide.Order).IsBindShieldOrder(oeordID_"||"_oeoriSub)
    }
    q:isBindShieldOrder=1 0
                
    // 医嘱开立日期时间
    s createDate=$p($g(^OEORD(oeordID,"I",oeoriSub,3)),"^",7)
    s createTime=$p($g(^OEORD(oeordID,"I",oeoriSub,1)),"^",17)
    
    // 按开医嘱时间查询
    s createOrderFlag=queryArgument.createOrderFlagGet()
    s quitFlag=0
    i createOrderFlag="true"{
        s startCreateDate=queryArgument.startCreateDateGet()
        s endCreateDate=queryArgument.endCreateDateGet()
        s startCreateTime=queryArgument.startCreateTimeGet()
        s endCreateTime=queryArgument.endCreateTimeGet()
        i (createDate<startCreateDate)||(createDate>endCreateDate) s quitFlag=1
        i (createDate=startCreateDate)&&(createTime<startCreateTime) s quitFlag=1
        i (createDate=endCreateDate)&&(createTime>endCreateTime) s quitFlag=1
    }
    q:$g(quitFlag)=1 0
    
    s newDisconFlag=queryArgument.newDisconFlagGet()
    s newCreateFlag=queryArgument.newCreateFlagGet()
    // 停医嘱时间
    s stopDate=$p($g(^OEORD(oeordID,"I",oeoriSub,3)),"^",34)
    // 没有停医嘱时间取预停时间
    s:stopDate="" stopDate= $p($g(^OEORD(oeordID,"I",oeoriSub,9)),"^",9)
    
    s curDate=+$h
    s quitFlag=0
    i (newDisconFlag="true")&&(newCreateFlag="false") {
        // 今日新停，过滤医嘱状态不是停止的
        i (ordStatID'=stopSateDr) s quitFlag=1
        // 过滤停止日期不是当天的  
        i (stopDate'=curDate) s quitFlag=1
    }elseif (newDisconFlag="false")&&(newCreateFlag="true"){
        // 今日新开，过滤开医嘱日期不是当天的
        i (createDate'=curDate) s quitFlag=1
    }elseif (newDisconFlag="true")&&(newCreateFlag="true"){
        // 今日新开和今日新开
        i ((ordStatID=stopSateDr)&&(stopDate'=curDate))||((ordStatID'=stopSateDr)&&(createDate'=curDate)) s quitFlag=1
    }
    q:$g(quitFlag)=1 0


    s wardID=queryArgument.wardIDGet()
    s ctcptType=queryArgument.ctcptTypeGet()
    s locID=queryArgument.locIDGet()
    s locType=queryArgument.locTypeGet()
    s curWardLinkDocFlag=..OrdWardLinkDoc(wardID, ctcptType, "", oeordID_"||"_oeoriSub)
    s curLocLinkDocFlag=..OrdLocLinkWard(locID, ctcptType, oeordID_"||"_oeoriSub,currentSheetSetting.GetAt("filterPreOrd"))
    //s sheetOnlyShowCurRecLocOrd=currentSheetSetting.GetAt("sheetOnlyShowCurRecLocOrd") //仅显示接收科室为本科室医嘱
    //s sheetShowAnaestheAllStageOrd=currentSheetSetting.GetAt("sheetShowAnaestheAllStageOrd") //显示麻醉师所有医嘱阶段医嘱
    //接收科室
    //s recLoc=$p($g(^OEORD(oeordID,"I",oeoriSub,3)),"^",6)
    //q:(sheetOnlyShowCurRecLocOrd="Y")&&(recLoc'=locID)
    //麻醉师医嘱标识
    s AnaesthOrdFlag=..isAnaestheOrd(oeordID_"||"_oeoriSub)
    //下医嘱科室
    s ordDep=$p($g(^OEORD(oeordID,"I",oeoriSub,7)),"^",2)
    s ordLocType=""
    i ordDep'="" s ordLocType=$p(^CTLOC(ordDep),"^",13)
        
    // 医嘱是否为病区关联科室申请的会诊医嘱
    s ifConsultOrd=##class(Nur.IP.DrugAudit).IfConsultOrd(locID, oeordID, oeoriSub) 
        
    // 获取医嘱阶段
    s stage=$p($g(^OEORD(oeordID,"I",oeoriSub,"DHC")),"^",8)
    if (ifDeliveryRoom=0) {
        // 过滤非本科本病区下的医护人员医嘱
        if (locType="OP") {
            q:(wardID'="")&&(curWardLinkDocFlag'="Y")&&(admVisitStatus'="P")&&(ifConsultOrd="N")&&(stage'="SZ")&&(stage'="SQ") 0
        }else{
            q:(curLocLinkDocFlag'="Y")&&(admVisitStatus'="P")&&(ifConsultOrd="N") 0
        }
    }else{
        // 如果当前病区为产房，则过滤掉非本科室医生所下的非产中医嘱
        q:(curLocLinkDocFlag'="Y")&&(stage'="CZ") 0
    }
    
#;  q:(wardID'="")&&(curWardLinkDocFlag'="Y")&&(locType="OP")&&(admVisitStatus'="P")&&(ifDeliveryRoom=0)&&(ifConsultOrd="N")&((stage'="SZ")||(stage'="SQ")) 0
#;  q:(curLocLinkDocFlag'="Y")&&(locType'="OP")&&(admVisitStatus'="P")&&(ifDeliveryRoom=0)&&(ifConsultOrd="N") 0
#;  q:(ifDeliveryRoom=1)&&(curLocLinkDocFlag'="Y")&&(stage'="CZ") 0


    // 获取医嘱处置状态(NeedToDeal:需处理医嘱，NeedToStop:需处理停止，AlreadyDeal:已处理，AlreadyStop:已处理停止)
    s disposeStatCode=##class(Nur.NIS.Service.Base.Order).GetOrderDisposeStatCode(oeordID, oeoriSub)
    
    // 获取用于过滤的医嘱信息
    s filterInfo=..InitFilterInfo(oeordID, oeoriSub, "")
    d filterInfo.SetAt(disposeStatCode, "disposeStatCode")
    d filterInfo.SetAt(AnaesthOrdFlag,"AnaesthOrdFlag")
    d filterInfo.SetAt(locID,"locID")
    
    // 过滤医嘱
    s filterFlag=..FilterOrder(oeordID, oeoriSub, "", filterInfo, queryArgument, currentSheetSetting)
    q:filterFlag=0 0
    
    // 当前单据不是需处理,保存有数据标记后退出
    i (isCurrentSheet=0) {
        //之前前写死的"DefaultSee",当多个需处理类型的单据，会出现问题:页签下面存在医嘱，但是没有红点标记20230606
        d orderObject.SetAt("true",sheetCode) //d orderObject.SetAt("true","DefaultSee") 
        q 0
    }
    // 获取主医嘱数据
    s orderInfo=..InitOrderInfo(oeordID, oeoriSub, "N", columns,colorsSetting,currentSheetSetting)
    d orderInfo.SetAt(disposeStatCode,"disposeStatCode")
    d orderInfo.SetAt(##class(%ListOfDataTypes).%New(),"childs")
    // 查询子医嘱
    s child=0  
    f 
    {
        s child=$O(^OEORDi(0,"OEORI",oeordID,oeordID_"||"_oeoriSub,child))
        i ("10012545||279")=(oeordID_"||"_oeoriSub) b
        q:child=""
        //过滤子医嘱
        s childDisposeStatCode=##class(Nur.NIS.Service.Base.Order).GetOrderDisposeStatCode(oeordID, child)
        s childFilterInfo=..InitFilterInfo(oeordID, child, "")
        d childFilterInfo.SetAt(childDisposeStatCode,"disposeStatCode")
        d childFilterInfo.SetAt(locID,"locID")
        s childFilterFlag=..FilterOrder(oeordID, child, "", childFilterInfo, queryArgument, currentSheetSetting)
        continue:childFilterFlag=0
        // 获取子主医嘱数据
        s childOrderInfo=..InitOrderInfo(oeordID,child,"Y",columns,colorsSetting,currentSheetSetting)
        // 将子医嘱数据插入到主医嘱的childs属性上
        d orderInfo.GetAt("childs").Insert(childOrderInfo)
    }
    
    // 按照标本号及处置状态合并医嘱
    s labNo=orderInfo.GetAt("labNo")
    i (labNo'="") {
        s mergeSameLabNoFlag=..MergeSameLabNo(labNo, disposeStatCode, orderInfo, .labData,queryArgument,columns,currentSheetSetting,"",colorsSetting)
        //合管并退出
        q:mergeSameLabNoFlag=1 0
    }
    q:('queryArgument.PageFilter()) 0 ;;;PDA分页
    // 日期时间节点
    s sortDateTime=createDate*86400+createTime
    // 医嘱ID节点
    s sortID=oeordID_"||"_oeoriSub
    s arcimSerialNo=..getArcimSerialNo(currentSheetSetting,orderInfo.GetAt("ID"))
    s ordersData(patIndex,arcimSerialNo_sortDateTime,oeordID,oeoriSub)=orderInfo
    q 0
}

ClassMethod getArcimSerialNo(sheetSetting, ordId)
{
    s sheetRowId=sheetSetting.GetAt("sheetRowId")
    s data=$g(^CF.NUR.NIS.NurseSheetSetD(sheetRowId))
    s sheetOrdSort=$lg(data,39)
    if (sheetOrdSort="Y"){
        s arcimID=$p($g(^OEORD(+ordId,"I",$p(ordId,"||",2),1)),"^",2)
        q:arcimID="" "z10000"
        s sortId=$o(^CF.NUR.NIS.ExecOrdSortSetI("EOSSArcimDRIndex",sheetRowId,arcimID,""))
        q:sortId="" "z10000"
        s serialNo=$lg(^CF.NUR.NIS.NurseSheetSetD(sheetRowId,"OrdSortSub",sortId),2)
        q:serialNo="" "z10000"
        q $e(serialNo,1,*)+100000
    }
    q ""
}

/// Description:    按照标本号及处置状态合并医嘱并返回是否合管标记
/// Input:          labNo：标本号，disposeStatCode：处置状态code
///                 orderInfo：医嘱信息，labData：记录同处置状态、同标本号合管医嘱
/// Return:         0为当前医嘱未合管，1为当前医嘱合管
/// Other:  
ClassMethod MergeSameLabNo(labNo, disposeStatCode, orderInfo, labData, queryArgument, columns, currentSheetSetting, examData, colorsSetting) As %Boolean
{
    n (labNo, disposeStatCode, orderInfo, labData,queryArgument,columns,currentSheetSetting,examData,colorsSetting,%session)
    q:$g(disposeStatCode)="" 0
    #dim sameLabNoOrderInfo as %ArrayOfDataTypes
    s sameLabNoOrderInfo=$g(labData(labNo,disposeStatCode))
    i sameLabNoOrderInfo=""{
        s labData(labNo,disposeStatCode)=orderInfo
        d orderInfo.SetAt(##class(%ListOfDataTypes).%New(),"sameLabNoOrders")
        ;;;PDA分页可能导致检验医嘱不能成组显示，这里直接遍历插入
        s ID=..GetOrdIdFromOrderInfo(orderInfo)
        s labOrdIdStr=..GetOrdIdStrByLabNo(labNo,"^")
        s labOrdIdLen=$l(labOrdIdStr,"^")
        i (labOrdIdLen=1) s labOrdIdLen=0
        f labOrdIdInd=1:1:labOrdIdLen {
            s labOrdId=$p(labOrdIdStr,"^",labOrdIdInd)
            s labOrdOew=+labOrdId,labOrdChl=$p(labOrdId,"||",2),labOrdSub=$p(labOrdId,"||",3)
            i ($l(ID,"||")=3) {
                continue:(labOrdId=ID)
                s labOrdDisposeStatCode=##class(Nur.NIS.Service.Base.Order).GetDisposeStatCode(labOrdOew,labOrdChl,labOrdSub)
                continue:(labOrdDisposeStatCode'=disposeStatCode)
                s labOrdInfo=..InitOrderInfo(labOrdOew,labOrdChl,"N",columns,colorsSetting,currentSheetSetting)
                d labOrdInfo.SetAt(##class(%ListOfDataTypes).%New(),"childs")
                d labOrdInfo.SetAt(##class(%ListOfDataTypes).%New(),"execInfos")
                d ..InitExec(labOrdOew,labOrdChl,labOrdSub,labOrdDisposeStatCode,queryArgument,columns,labOrdInfo,currentSheetSetting,1,.examData,colorsSetting)
            } else {
                continue:(labOrdOew_"||"_labOrdChl=ID)
                s labOrdDisposeStatCode=##class(Nur.NIS.Service.Base.Order).GetOrderDisposeStatCode(labOrdOew,labOrdChl)
                continue:(labOrdDisposeStatCode'=disposeStatCode)
                s labOrdInfo=..InitOrderInfo(labOrdOew,labOrdChl,"N",columns,colorsSetting,currentSheetSetting)
            }
            ;;;i (labOrdInfo.GetAt("doubleSign")="Y") d sameLabNoOrderInfo.SetAt("Y","doubleSign")
            d orderInfo.GetAt("sameLabNoOrders").Insert(labOrdInfo)
        }
    } else {
        q 1 ;;;已经插入过
    }
    q:sameLabNoOrderInfo="" 0
    ;;;if (orderInfo.GetAt("doubleSign")="Y"){
        ;;;d sameLabNoOrderInfo.SetAt("Y","doubleSign")
    ;;;}
    d sameLabNoOrderInfo.GetAt("sameLabNoOrders").Insert(orderInfo)
#;  i $g(labDataI(labNo,disposeStatCode))'="" {
#;      s mergeLabEpisodeID=$lg(labDataI(labNo,disposeStatCode),1)
#;      s mergeLabDateTime=$lg(labDataI(labNo,disposeStatCode),2)
#;      s mergeLabID=$lg(labDataI(labNo,disposeStatCode),3)
#;      #dim mergeLabOrderInfo As %ArrayOfDataTypes
#;      s mergeLabOrderInfo=ordersData(mergeLabEpisodeID,mergeLabDateTime,mergeLabID)
#;      d mergeLabOrderInfo.GetAt("sameLabNoOrders").Insert(orderInfo)
#;      q 1
#;  }else{
#;      s labDataI(labNo,disposeStatCode)=$lb(episodeID,sortDateTime,sortID)
#;      d orderInfo.SetAt(##class(%ListOfDataTypes).%New(),"sameLabNoOrders")
#;  }
    q 1
}

/// PDA新增--通过标本号取医嘱号
ClassMethod GetOrdIdStrByLabNo(labNo, del, check, return) As %String
{
    n (labNo,del,check,return)
    q:(labNo="") ""
    d Delimiter
    i (labNo["-") d
    .s oeoriId=$p(labNo,";"),oew=+oeoriId,chl=$p(oeoriId,"-",2)
    .s pisId=$o(^DHCAPPPM(0,"OrdItem",oew_"||"_chl,""))
    .i ($g(pisId)'="") s pisSub=$o(^DHCAPPPM(pisId,"A",""))
    .i ($g(pisSub)'="") s pisOrdId=$p(^DHCAPPPM(pisId,"A",pisSub),"^",3)
    .q:($g(pisOrdId)="")
    .s oew=+pisOrdId,chl=+$p(pisOrdId,"||",2),sub=$o(^OEORD(oew,"I",chl,"X",0))
    .i (sub'="")&(return="ore") s $p(pisOrdId,"||",3)=sub
    .i (check=1)&&('..CheckStat(pisOrdId)) s pisOrdId=""
    q:(labNo["||")||(labNo["-") $g(pisOrdId)
    s (sample,labOrdStr)=""
    i ($o(^OEORDi(0,"PlacerNo",labNo,""))'="") d
    .s placerNo=labNo,labNo=$o(^OEORDi(0,"PlacerNo",placerNo,""))
    .s oew=0 f  s oew=$o(^OEORDi(0,"PlacerNo",placerNo,labNo,oew)) q:(oew="")  d
    ..s chl=0 f  s chl=$o(^OEORDi(0,"PlacerNo",placerNo,labNo,oew,chl)) q:(chl="")  d
    ...i (labOrdStr'="") s labOrdStr=labOrdStr_del
    ...s labOrdStr=labOrdStr_oew_"||"_chl
    e  i ($d(^OEORD(0,"EpisNo",labNo))) d
    .s oew=0 f  s oew=$o(^OEORD(0,"EpisNo",labNo,oew)) q:(oew="")  d
    ..s chl=0 f  s chl=$O(^OEORD(0,"EpisNo",labNo,oew,chl)) q:(chl="")  d
    ...i (labOrdStr'="") s labOrdStr=labOrdStr_del
    ...s labOrdStr=labOrdStr_oew_"||"_chl
    q:(labOrdStr="") labOrdStr
    s len=$l(labOrdStr,del)
    f ind=1:1:len d
    .s labOrd=$p(labOrdStr,del,ind)
    .s oew=$p(labOrd,"||"),chl=$p(labOrd,"||",2)
    .s sub=$o(^OEORD(oew,"I",chl,"X",0))
    .i (sub'="")&&(return="ore") s labOrd=labOrd_"||"_sub
    .q:(check=1)&&('..CheckStat(labOrd))
    .i (sample'="") s sample=sample_del
    .s sample=sample_labOrd
    q sample
Delimiter
    i ($g(del)="") s del="^"
    i ($g(subdel)="") s subdel="^"
    i ($g(lab)="") s lab="0"
    i ($g(check)="") s check="0"
    i ($g(return)="") s return="ore"
    q
}

ClassMethod CheckStat(oeoreId) As %String
{
    n (oeoreId)
    s l=$l(oeoreId,"||")
    i (l=3) {
        s stat=..GetOrdOrExecStatCode(oeoreId)
        q:(stat="D") 0
    } elseif (l=2) {
        s stat=..GetOrdOrExecStatCode(oeoreId)
        q:(stat="U")||(stat="D")||(stat="C") 0
    }
    q 1
}

ClassMethod GetOrdOrExecStatCode(oeoreId) As %String
{
    n (oeoreId)
    s oew=+oeoreId,chl=+$p(oeoreId,"||",2),sub=$p(oeoreId,"||",3)
    q:(chl="") ""
    s statCode=""
    i (sub="") d
    .s ordStatId=$p($g(^OEORD(oew,"I",chl,1)),"^",13)
    .i (ordStatId'="") s statCode=$p($g(^OEC("OSTAT",ordStatId)),"^",1)
    e  d
    .s execStatusId=$p($g(^OEORD(oew,"I",chl,"X",sub)),"^",16)
    .i (execStatusId'="") s statCode=$p($g(^OEC("STAT",execStatusId)),"^",1)
    q statCode
}

/// PDA新增--
ClassMethod GetOrdIdFromOrderInfo(orderInfo) As %String
{
    n (orderInfo)
    s ordId=""
    ;;;按执行记录
    i (orderInfo.IsDefined("execInfos")) {
        s execInfos=orderInfo.GetAt("execInfos")
        s execCount=execInfos.Count()
        i (execCount>0) {
            s execInfo=execInfos.GetAt(1)
            s ordId=execInfo.GetAt("ID")
        }
    ;;;按医嘱
    } else {
        s ordId=orderInfo.GetAt("ID")
    }
    q ordId
}

/// Description:    获取前端选中单据下医嘱信息并判断非DefaultSee、非BHYZD的其他单据下是否有医嘱
/// Input:          episodeID：当前患者就诊号，sheetCode：单据Code
///                 queryArgument：查询参数对象，ifDeliveryRoom：当前是否是产房(1:是产房、0:不是产房)
///                 admVisitStatus：患者状态，columns：列数组
///                 sheetsSetting：非需处理及非当前单据外的其他单据的筛选条件，isCurrentSheet：当前单据是否为前端选中单据(1:是、0:不是)
///                 orderObject：记录其他单据是否有医嘱的对象，ordersData：前端选中单据医嘱数据
///                 labData：记录同处置状态、同标本号合管医嘱，examData：记录同检查部位ID，同医嘱ID合并医嘱
/// Return:         
/// Other:  
ClassMethod GetOtherSheetOrders(episodeID, patIndex, sheetCode, queryArgument As OrderParam, ifDeliveryRoom, admVisitStatus, columns As %ListOfDataTypes, sheetsSetting As %ListOfDataTypes, isCurrentSheet, orderObject As %ArrayOfDataTypes, ordersData, labData, examData, colorsSetting As %ListOfDataTypes) As %String
{
    n (episodeID, patIndex, sheetCode, queryArgument, ifDeliveryRoom,admVisitStatus, columns, sheetsSetting, isCurrentSheet, orderObject, ordersData, labData, examData,colorsSetting,%session)
    
    s oeordID=$o(^OEORD(0,"Adm",episodeID,0)) 
    q:oeordID="" 0
    
    s createOrderFlag=queryArgument.createOrderFlagGet()
    s startDate=queryArgument.startDateGet()
    s startTime=queryArgument.startTimeGet()
    s endDate=queryArgument.endDateGet()
    s endTime=queryArgument.endTimeGet()
    s wardID=queryArgument.wardIDGet()
    s ctcptType=queryArgument.ctcptTypeGet()
    s locID=queryArgument.locIDGet()
    s locType=queryArgument.locTypeGet()
    s hospID=queryArgument.hospIDGet()
    s startCreateDate=queryArgument.startCreateDateGet()
    s endCreateDate=queryArgument.endCreateDateGet()
    s startCreateTime=queryArgument.startCreateTimeGet()
    s endCreateTime=queryArgument.endCreateTimeGet()
    s newDisconFlag=queryArgument.newDisconFlagGet()
    s newCreateFlag=queryArgument.newCreateFlagGet()
    
    // 获取当前单据的过滤条件
    s sheetCodeLen=$l(sheetCode,"^")
    i ('queryArgument.PDAMulti) {
        s currentSheetSetting=..GetSheetSetting(sheetCode,hospID)
        s sheetType=currentSheetSetting.GetAt("sheetType")
        q:(sheetType="DefaultSee")||(sheetType="BGYZD") 0
    } else {
        s currentSheetSetting=##class(%ListOfDataTypes).%New()
        f sheetCodeInd=1:1:sheetCodeLen {
            s sheetCodeFor=$p(sheetCode,"^",sheetCodeInd)
            continue:(sheetCodeFor="")
            s sheetSettingFor=..GetSheetSetting(sheetCodeFor,hospID)
            s sheetTypeFor=currentSheetSetting.GetAt("sheetType")
            continue:(sheetTypeFor="DefaultSee")||(sheetTypeFor="BGYZD")
            d currentSheetSetting.Insert(sheetSettingFor)
        }
    }
    i (oeordID=7601) b
    
    for ordSttDate=startDate:1:endDate
    {
        s ordSttTime=""
        for
        {
            s ordSttTime=$o(^OEORDi(0,"Date",oeordID,ordSttDate,ordSttTime))
            q:ordSttTime=""
            // 过滤要求执行时间大于查询开始时间医嘱
            continue:(ordSttDate=startDate)&(ordSttTime<startTime)
            // 当要求执行时间大于查询结束时间医嘱停止循环
            q:(ordSttDate=endDate)&(ordSttTime>endTime)
            s oeoriSub=0
            for
            {
                s oeoriSub=$o(^OEORDi(0,"Date",oeordID,ordSttDate,ordSttTime,oeoriSub))
                q:oeoriSub=""
                s oeoreFirst=$o(^OEORD(oeordID,"I",oeoriSub,"X",0))
                q:oeoreFirst=""
                i ("10012545||163")=(oeordID_"||"_oeoriSub) b
                
                // 过滤子医嘱
                s ordSeqID=$p($g(^OEORD(oeordID,"I",oeoriSub,11)),"^",39)
                continue:ordSeqID'=""
                
                // 过滤绑定需屏蔽医嘱
                s MethodParam=$g(^oddCOM("Nur.Interface.OutSide.Order","m","IsBindShieldOrder",60))
                i $lg($lg(MethodParam,1),1)="sheetCode" {
                    s isBindShieldOrder=##Class(Nur.Interface.OutSide.Order).IsBindShieldOrder(sheetCode,oeordID_"||"_oeoriSub)
                }else {
                     s isBindShieldOrder=##Class(Nur.Interface.OutSide.Order).IsBindShieldOrder(oeordID_"||"_oeoriSub)
                }
                continue:isBindShieldOrder=1
                
                // 开医嘱医嘱时间
                s createDate=$p($g(^OEORD(oeordID,"I",oeoriSub,3)),"^",7)
                s createTime=$p($g(^OEORD(oeordID,"I",oeoriSub,1)),"^",17)
                
                // 日期时间节点
                s sortDateTime=createDate*86400+createTime
                // 医嘱ID节点
                s sortID=oeordID_"||"_oeoriSub
                s oeoreSttDate=$p($g(^OEORD(oeordID,"I",oeoriSub,"X",oeoreFirst)),"^",1)
                s plusOneFlag=(ordSttDate=oeoreSttDate)&(oeoreSttDate=($p($g(^OEORD(oeordID,"I",oeoriSub,1)),"^",9)+1))
                q:((ordSttDate=(endDate+1))&('plusOneFlag))
                
                s stopSateDr=$O(^OEC("OSTAT",0,"Code","D",""))
                s ordStatID=$p($g(^OEORD(oeordID,"I",oeoriSub,1)),"^",13)
                
                // 过滤要求执行时间大于停止时间的执行记录
                // 停医嘱日期时间
                s stopDate=$p($g(^OEORD(oeordID,"I",oeoriSub,3)),"^",34)
                s stopTime=$p($g(^OEORD(oeordID,"I",oeoriSub,2)),"^",15)
                // 没停止日期时,取预停日期
                s:stopDate="" stopDate=$p($g(^OEORD(oeordID,"I",oeoriSub,9)),"^",9)
                s:stopTime="" stopTime=$p($g(^OEORD(oeordID,"I",oeoriSub,9)),"^",10) 
                continue:((ordSttDate>stopDate)!((ordSttDate=stopDate)&&(ordSttTime>stopTime)))&&(stopDate'="")&&(stopTime'="")
                // 判断是否已经存在该医嘱(如存在则无须进行以下判断)
                i $g(orderFilter(episodeID,oeordID,oeoriSub))'="Y" {    
                    s quitFlag=0
                    i createOrderFlag="true"{
                        i (createDate<startCreateDate)!(createDate>endCreateDate) s quitFlag=1
                        i (createDate=startCreateDate)&&(createTime<startCreateTime) s quitFlag=1
                        i (createDate=endCreateDate)&&(createTime>endCreateTime) s quitFlag=1
                    }
                    continue:$g(quitFlag)=1
                    s curDate=+$h
                    s quitFlag=0
                    i (newDisconFlag="true")&&(newCreateFlag="false") {
                        // 今日新停，过滤医嘱状态不是停止的
                        i (ordStatID'=stopSateDr) s quitFlag=1
                        // 过滤停止日期不是当天的  
                        i (stopDate'=curDate) s quitFlag=1
                    }elseif (newDisconFlag="false")&&(newCreateFlag="true") {
                        // 今日新开，过滤开医嘱时间不等于当前时间的医嘱
                        i (createDate'=curDate) s quitFlag=1
                    }elseif (newDisconFlag="true")&&(newCreateFlag="true"){
                        // 今日新开和今日新开
                        i ((ordStatID=stopSateDr)&&(stopDate'=curDate))||((ordStatID'=stopSateDr)&&(createDate'=curDate)) s quitFlag=1
                    }
                    continue:$g(quitFlag)=1
                
                    // 过滤医嘱状态为空的医嘱
                    s ordStatID=$P($G(^OEORD(oeordID,"I",oeoriSub,1)),"^",13) 
                    continue:ordStatID=""
                
                    //过滤护士没核对的医嘱
                    s seeType=$P($G(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",7)
                    continue:(seeType'="A")&(seeType'="F")&(locType'="OP")&(admVisitStatus'="P")
    
                    s curWardLinkDocFlag=..OrdWardLinkDoc(wardID, ctcptType, "", oeordID_"||"_oeoriSub)
                    s curLocLinkDocFlag=..OrdLocLinkWard(locID, ctcptType, oeordID_"||"_oeoriSub,currentSheetSetting.GetAt("filterPreOrd"))
                    //s sheetOnlyShowCurRecLocOrd=currentSheetSetting.GetAt("sheetOnlyShowCurRecLocOrd") //仅显示接收科室为本科室医嘱
                    //s sheetShowAnaestheAllStageOrd=currentSheetSetting.GetAt("sheetShowAnaestheAllStageOrd") //显示麻醉师所有医嘱阶段医嘱
                    //接收科室
                    //s recLoc=$p($g(^OEORD(oeordID,"I",oeoriSub,3)),"^",6)
                    //continue:(sheetOnlyShowCurRecLocOrd="Y")&&(recLoc'=locID)
                    //麻醉师医嘱标识
                    s AnaesthOrdFlag=..isAnaestheOrd(oeordID_"||"_oeoriSub)
                    //下医嘱科室
                    s ordDep=$p($g(^OEORD(oeordID,"I",oeoriSub,7)),"^",2)
                    s ordLocType=""
                    i ordDep'="" s ordLocType=$p(^CTLOC(ordDep),"^",13)
                    // 医嘱是否为病区关联科室申请的会诊医嘱
                    s ifConsultOrd=##class(Nur.IP.DrugAudit).IfConsultOrd(locID, oeordID, oeoriSub) 
                    // 获取医嘱阶段
                    s stage=$p($g(^OEORD(oeordID,"I",oeoriSub,"DHC")),"^",8)
                    if (ifDeliveryRoom=0) {
                        // 过滤非本科本病区下的医护人员医嘱
                        if (locType="OP") {
                            continue:(wardID'="")&&(curWardLinkDocFlag'="Y")&&(admVisitStatus'="P")&&(ifConsultOrd="N")&(stage'="SZ")&(stage'="SQ") //&&(stage'="ALL")
                        }else{
                            continue:(curLocLinkDocFlag'="Y")&&(admVisitStatus'="P")&&(ifConsultOrd="N") //&&(stage'="ALL")
                        }
                    }else{
                        // 如果当前病区为产房，则过滤掉非本科室医生所下的非产中医嘱
                        continue:(curLocLinkDocFlag'="Y")&&(stage'="CZ") //&&(stage'="ALL") 
                    }
                    s orderFilter(episodeID,oeordID,oeoriSub)="Y"
                }
                s oeoreSub=0
                for
                {
                    s oeoreSub=$o(^OEORDi(0,"Date",oeordID,ordSttDate,ordSttTime,oeoriSub,oeoreSub))
                    q:oeoreSub=""
                    continue:ordSttDate>endDate
                    // Needless:不需执行,Immediate:需处理即刻,LongNew:新开长嘱,Temp:需处理临嘱,Discontinue:需处理停止
                    // Exec:已执行,ExecDiscon:已处理停止,LongUnnew:非新长嘱,SkinTest:皮试,SkinTestNorm:皮试阴性,SkinTestAbnorm:皮试阳性
                    s disposeStatCode=##class(Nur.NIS.Service.Base.Order).GetDisposeStatCode(oeordID,oeoriSub,oeoreSub)
                    s filterInfo=..InitFilterInfo(oeordID,oeoriSub,oeoreSub)
                    d filterInfo.SetAt(disposeStatCode,"disposeStatCode")
                    d filterInfo.SetAt(AnaesthOrdFlag,"AnaesthOrdFlag")
                    d filterInfo.SetAt(locID,"locID")
                    // 判断是否满足其他单据的过滤条件
                    ;;;s i=0
                    ;;;while i<sheetsSetting.Count() {
                        ;;;s i=i+1
                        ;;;#dim otherSheetSetting As %ArrayOfDataTypes
                        ;;;s otherSheetSetting=sheetsSetting.GetAt(i)
                        ;;;continue:$IsObject(otherSheetSetting)=0
                        ;;;s otherSheetCode=otherSheetSetting.GetAt("Code")
                        ;;;s otherSheetType=otherSheetSetting.GetAt("sheetType")
                        ;;;continue:(otherSheetType="DefaultSee")||(otherSheetType="BGYZD")
                        ;;;s otherSheetFilterFlag=..FilterOrder(oeordID,oeoriSub,oeoreSub,filterInfo,queryArgument,otherSheetSetting)
                        ;;;continue:otherSheetFilterFlag=0
                        // 满足则保存有数据标记，并在非当前及DefaultSee单据数组中去除该单据
                        ;;;d orderObject.SetAt("true",otherSheetCode)
                        ;;;s actLen=sheetsSetting.Count()
                        ;;;s lastItem=sheetsSetting.GetAt(actLen)
                        ;;;d sheetsSetting.SetAt(lastItem,i)
                        ;;;d sheetsSetting.RemoveAt(actLen)
                        ;;;s i=i-1
                    ;;;}
                    ;;;continue:isCurrentSheet="0"
                    
                    // 判断该条执行记录是否满足当前单据过滤条件
                    ;;;s currentSheetSettingTemp=##class(Nur.JSON).Encode(currentSheetSetting)
                    i (queryArgument.PDAMulti'=1) {
                        s filterFlag=..FilterOrder(oeordID, oeoriSub, oeoreSub, filterInfo, queryArgument, currentSheetSetting)
                        i ("10012545||163||1"=(oeordID_"||"_oeoriSub_"||"_oeoreSub)) b
                        continue:filterFlag=0
                        s sheetSettingFor=currentSheetSetting
                    } else {
                        s filterFlag=0
                        s sheetSettingLen=currentSheetSetting.Count()
                        f sheetSettingInd=1:1:sheetSettingLen {
                            s sheetSettingFor=currentSheetSetting.GetAt(sheetSettingInd)
                            s filterFlag=..FilterOrder(oeordID, oeoriSub, oeoreSub, filterInfo, queryArgument, sheetSettingFor)
                            i ("7601||17||33"=(oeordID_"||"_oeoriSub_"||"_oeoreSub)) b
                            q:(filterFlag=1)
                        }
                        continue:filterFlag=0
                    }
                    continue:('queryArgument.PageFilter()) ;;;PDA分页
                    
                    // 判断该条执行记录的主医嘱是否已经插入ordersData
                    s arcimSerialNo=..getArcimSerialNo(sheetSettingFor,oeordID_"||"_oeoriSub)
                    s orderInfo=$g(ordersData(patIndex,arcimSerialNo_sortDateTime,oeordID,oeoriSub))
                    i orderInfo="" {
                        // 未插入则查询主医嘱信息
                        s orderInfo=..InitOrderInfo(oeordID, oeoriSub, "N", columns,colorsSetting,sheetSettingFor)
                        ;;;s doubleSign=..IsDoubleSignOrderGroup(oeordID, oeoriSub, hospID)
                        ;;;d orderInfo.SetAt(doubleSign,"doubleSign")
                        d orderInfo.SetAt(##class(%ListOfDataTypes).%New(),"childs")
                        d orderInfo.SetAt(##class(%ListOfDataTypes).%New(),"execInfos")
                        // 查询执行记录信息
                        d ..InitExec(oeordID, oeoriSub, oeoreSub, disposeStatCode, queryArgument, columns, orderInfo, sheetSettingFor, 1, .examData,colorsSetting)
                        //按照标本号合并医嘱
                        s labNo=orderInfo.GetAt("labNo")
                        i (labNo'="") {
                            s mergeSameLabNoFlag=..MergeSameLabNo(labNo, disposeStatCode, orderInfo, .labData,queryArgument,columns,sheetSettingFor,.examData,colorsSetting)
                            //合并过标本的医嘱不需要插入到ordersData中
                            continue:mergeSameLabNoFlag=1 
                        }
                        s ordersData(patIndex,arcimSerialNo_sortDateTime,oeordID,oeoriSub)=orderInfo
                    }else{
                        d ..InitExec(oeordID, oeoriSub, oeoreSub, disposeStatCode, queryArgument, columns, orderInfo, sheetSettingFor, 0, .examData,colorsSetting)
                    }
                    return:(queryArgument.PDAAtEnd=1)
                }
            }
        }
    }
}

/// Description:    获取执行记录信息及子医嘱信息
/// Input:          oeordID，oeoriSub，oeoreSub：执行记录ID，disposeStatCode：处置状态code，queryArgument：查询参数对象
///                 columns：列数组，orderInfo：主医嘱信息，currentSheetSetting：当前单据的过滤条件
///                 addChildOrderInfoFlag，：examData：记录同检查部位ID，同医嘱ID合并医嘱
/// Return:         
/// Other:  
ClassMethod InitExec(oeordID, oeoriSub, oeoreSub, disposeStatCode, queryArgument As OrderParam, columns As %ListOfDataTypes, orderInfo As %ArrayOfDataTypes, currentSheetSetting As %ArrayOfDataTypes, addChildOrderInfoFlag, examData, colorsSetting As %ListOfDataTypes)
{
    n (oeordID, oeoriSub, oeoreSub, disposeStatCode, queryArgument, columns, orderInfo, currentSheetSetting, addChildOrderInfoFlag, examData, colorsSetting,currentSheetSetting,%session)
    s excutedOrderFlag=queryArgument.excutedOrderFlagGet()
    s hospID=queryArgument.hospIDGet()
    s locID=queryArgument.locIDGet()
    // 获取执行记录信息
    s orderExecInfo=..InitOrderExecInfo(oeordID,oeoriSub,oeoreSub,excutedOrderFlag,columns,colorsSetting,currentSheetSetting)
    s examInfo=orderExecInfo.GetAt("examInfo")
    i (examInfo'="") {
        s partID=examInfo.GetAt("partID")
        i (partID'="") {
            // 根据检查部位ID及医嘱ID合并医嘱
            s mergeSameExamPartFlag=..MergeSameExamPartID(partID, oeordID, oeoriSub, orderExecInfo, .examData)
            q:mergeSameExamPartFlag=1 0
        }
    }
    //医嘱背景色
    ;;;s backgroundColor=..GetBackgroundColor(oeordID, oeoriSub, oeoreSub,colorsSetting)
    ;;;d orderExecInfo.SetAt(backgroundColor,"backgroundColor")
    d orderInfo.GetAt("execInfos").Insert(orderExecInfo)
    s orderExecChildID=##class(%ListOfDataTypes).%New()
    d orderExecInfo.SetAt(orderExecChildID,"childs")
    s childOrderExecInfo=##class(%ListOfDataTypes).%New()
    d orderExecInfo.SetAt(childOrderExecInfo,"childsexecInfos")
    d orderExecInfo.SetAt(disposeStatCode,"disposeStatCode")
    //查询子医嘱执行记录
    s child=0 
    for
    {
        s mainOeoreID=oeordID_"||"_oeoriSub_"||"_oeoreSub
        s child=$o(^OEORDi(0,"OEORE",mainOeoreID,oeordID,child))
        q:child=""
        s childSub=0  
        for 
        {
            s childSub=$o(^OEORDi(0,"OEORE",mainOeoreID,oeordID,child,childSub))
            q:childSub=""        
            
            // 过滤绑定需屏蔽医嘱
            s MethodParam=$g(^oddCOM("Nur.Interface.OutSide.Order","m","IsBindShieldOrder",60))
            i $lg($lg(MethodParam,1),1)="sheetCode" {
                s isBindShieldOrder=##Class(Nur.Interface.OutSide.Order).IsBindShieldOrder(currentSheetSetting.GetAt("sheetCode"),oeordID_"||"_child)
            }else {
                 s isBindShieldOrder=##Class(Nur.Interface.OutSide.Order).IsBindShieldOrder(oeordID_"||"_child)
            }
            continue:isBindShieldOrder=1
                   
            //过滤子医嘱
            s childExecFilterInfo=..InitFilterInfo(oeordID, child, childSub)
            s childExecDisposeStatCode=##class(Nur.NIS.Service.Base.Order).GetDisposeStatCode(oeordID,child,childSub)
            d childExecFilterInfo.SetAt(childExecDisposeStatCode,"disposeStatCode")
            d childExecFilterInfo.SetAt(locID,"locID")
            s childExecFilterFlag=..FilterOrder(oeordID, child, childSub, childExecFilterInfo, queryArgument, currentSheetSetting)
            continue:childExecFilterFlag=0
            d orderExecChildID.Insert(oeordID_"||"_child_"||"_childSub)
            d childOrderExecInfo.Insert(..InitOrderExecInfo(oeordID,child,childSub,excutedOrderFlag,columns,colorsSetting,currentSheetSetting))
            // 判断是否插入子医嘱
            
            i (addChildOrderInfoFlag=1) {
                // 获取子医嘱信息
                s childOrderInfo=..InitOrderInfo(oeordID, child, "Y", columns,colorsSetting,currentSheetSetting)
                d orderInfo.GetAt("childs").Insert(childOrderInfo)
            }
         }
    }
    q 0
}

/// Description:    根据检查部位ID及医嘱ID合并医嘱并返回是否合并标记
/// Input:          partID：检查部位ID，oeordID，oeoriSub：医嘱ID，orderExecInfo：执行记录信息，examData：记录同检查部位ID，同医嘱ID合并医嘱
/// Return:         
/// Other:  
ClassMethod MergeSameExamPartID(partID, oeordID, oeoriSub, orderExecInfo As %ArrayOfDataTypes, examData) As %Boolean
{
    n (partID, oeordID, oeoriSub, orderExecInfo, examData)
    #dim samePartExecInfo as %ArrayOfDataTypes
    s samePartExecInfo=$g(examData(partID,oeordID,oeoriSub))
    i (samePartExecInfo="") {
        s examData(partID,oeordID,oeoriSub)=orderExecInfo
        d orderExecInfo.SetAt(##class(%ListOfDataTypes).%New(),"samePartExecInfos")
    }
    q:samePartExecInfo="" 0
    d samePartExecInfo.GetAt("samePartExecInfos").Insert(orderExecInfo)
    q 1
}

/// Description:    获取用于过滤的医嘱信息
/// Input:          oeordID，oeoriSub，oeoreSub：执行记录ID，queryArgument：查询参数对象
/// Return:         
/// Other:          
ClassMethod InitFilterInfo(oeordID, oeoriSub, oeoreSub = "") As %ArrayOfDataTypes
{
    n (oeordID, oeoriSub, oeoreSub)     
    s filterInfo=##class(%ArrayOfDataTypes).%New()
    // 医嘱项
    s arcimID=$p($g(^OEORD(oeordID,"I",oeoriSub,1)),"^",2)
    s arcicID=$p($g(^ARCIM(+arcimID,$p(arcimID,"||",2),1)),"^",10)
    d filterInfo.SetAt(arcicID,"arcicID")
    // 医嘱子类
    s orcatID=""
    i arcicID'="" s arcicID=+arcicID,orcatID=$p($g(^ARC("IC",arcicID)),"^",8)
    d filterInfo.SetAt(orcatID,"orcatID")
    // 医嘱优先级
    s oecprID=$p($g(^OEORD(oeordID,"I",oeoriSub,1)),"^",8)
    d filterInfo.SetAt(oecprID,"oecprID")
    s ifShortOrderPrior=##class(appcom.OEOrdItem).ISShortOrderPrior(oecprID)
    d filterInfo.SetAt(ifShortOrderPrior,"ifShortOrderPrior")
    // 医嘱用法
    s phcinID=$p($g(^OEORD(oeordID,"I",oeoriSub,2)),"^",7) 
    d filterInfo.SetAt(phcinID,"phcinID")
    // 标本名称
    s specCode=$p($g(^OEORD(oeordID,"I",oeoriSub,"SPEC",1)),"^")
    d filterInfo.SetAt(specCode,"specCode")
    d filterInfo.SetAt("","SpecimenDR")
    if (specCode'="") {
        s RecDr=$P($G(^OEORD(oeordID,"I",oeoriSub,3)),"^",6)
        s HospitalId=$P($G(^CTLOC(+RecDr)),"^",22)
        i HospitalId'="" s HospitalId=##class(web.DHCBL.BDP.BDPMappingHOSP).GetDefHospIdByTableName("dbo.BT_Specimen",HospitalId,"")
        s HospitalCode=##class(web.DHCDocOrderCommon).GetCurrentSYSHospitalCode(HospitalId)
        s SpecimenDR=$p(##Class(DHCLIS.DHCCommon).GetSpecimen(specCode,$g(HospitalCode)),$c(2),1) 
        d filterInfo.SetAt(SpecimenDR,"SpecimenDR")
    }   
    // 接受科室
    s reclocID=$p($g(^OEORD(oeordID,"I",oeoriSub,3)),"^",6)
    d filterInfo.SetAt(reclocID,"reclocID")
    
    // 医嘱阶段
    s stage=$p($g(^OEORD(oeordID,"I",oeoriSub,"DHC")),"^",8)
    s:stage="" stage="PT"
    d filterInfo.SetAt(stage,"stage")
    s printFlag=""
    i (oeoreSub'="") {
        // 医嘱状态
        s ordStatusID=$p($g(^OEORD(oeordID,"I",oeoriSub,"X",oeoreSub,"BILL")),"^",1)
        // 执行状态
        s execStatusID=$p($g(^OEORD(oeordID,"I",oeoriSub,"X",oeoreSub)),"^",16) 
        // 打印标记
        s printFlag=$p($g(^OEORD(oeordID,"I",oeoriSub,"X",oeoreSub,"NUR")),"^",1)
    }else{
        // 医嘱状态
        s ordStatusID=$p($G(^OEORD(oeordID,"I",oeoriSub,1)),"^",13) 
        s printFlag=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",12)
    }
    d filterInfo.SetAt(ordStatusID,"ordStatusID")
    d filterInfo.SetAt(printFlag,"printFlag")
    //开医嘱人是医生/护士
    s userId=$P($G(^OEORD(oeordID,"I",oeoriSub,7)),"^",1)
    if (userId'=""){
        s ctcpId=$P($g(^SSU("SSUSR",userId)),"^",14)
        if (ctcpId'=""){
            s ctcptId=$P($G(^CTPCP(ctcpId,1)),"^",4)  ;CTPCP_CarPrvTp_DR
            s:ctcptId'="" ctcptType=$P($g(^CT("CPT",ctcptId)),"^",4)  ;CT_CarPrvTp
        }
    }
    d filterInfo.SetAt($g(ctcptType),"ctcptType")
    q filterInfo
}

/// Description:    获取医嘱信息并按当前单据的过滤条件过滤
/// Input:          oeordID，oeoriSub，oeoreSub：执行记录ID，filterInfo：用于过滤的医嘱信息
///                 queryArgument：查询参数对象，currentSheetSetting：当前单据的过滤条件
/// Return:         0为不满足条件(过滤)，1为满足条件
/// Other:
ClassMethod FilterOrder(oeordID, oeoriSub, oeoreSub = "", filterInfo As %ArrayOfDataTypes, queryArgument As OrderParam, currentSheetSetting As %ArrayOfDataTypes)
{
    n (oeordID, oeoriSub, oeoreSub, filterInfo, queryArgument, currentSheetSetting)
#;  s orcatID=filterInfo.GetAt("orcatID")   
    s disposeStatCode=filterInfo.GetAt("disposeStatCode")
    q:disposeStatCode="" 0
    //通用配置-过滤治疗类医嘱
    if (currentSheetSetting.GetAt("sheetCode")'="DefaultSee"){
        s filterCureApplyOrd=currentSheetSetting.GetAt("filterCureApplyOrd")
        if (filterCureApplyOrd="Y"){
            s cureAppRowId=##class(DHCDoc.DHCDocCure.OutInterface).GetCureApplyByOrd(oeordID_"||"_oeoriSub)
            q:cureAppRowId'="" 0
        }
    }
    //过滤医嘱项
    s FilterArcims=currentSheetSetting.GetAt("FilterArcims")
    if (FilterArcims'="") {
        s arcimID=$p($g(^OEORD(oeordID,"I",oeoriSub,1)),"^",2)
        s FilterArcims="^"_FilterArcims_"^"
        q:(FilterArcims[("^"_arcimID_"^")) 0
    }
    // 长期临时
    s longOrderFlag=queryArgument.longOrderFlagGet()
    s tempOrderFlag=queryArgument.tempOrderFlagGet()
    s ifShortOrderPrior=filterInfo.GetAt("ifShortOrderPrior")
    q:(longOrderFlag="true")&&(tempOrderFlag="false")&&(ifShortOrderPrior=1) 0
    q:(longOrderFlag="false")&&(tempOrderFlag="true")&&(ifShortOrderPrior=0) 0
    
    // 是否打印
    s printFlag=filterInfo.GetAt("printFlag")
    //已打印筛选标记
    s printFilterSings=currentSheetSetting.GetAt("printFilterSings")
    s printFlagFilterRule=currentSheetSetting.GetAt("printFlagFilterRule")
    //未打印筛选标记
    s notPrintFilterSings=currentSheetSetting.GetAt("notPrintFilterSings")
    s notPrintFlagFilterRule=currentSheetSetting.GetAt("notPrintFlagFilterRule")
    s ifPrint=queryArgument.ifPrintGet()
    //q:(ifPrint="true")&&(printFlag="") 0 //(oeoreSub'="")&&
    if (oeoreSub'="")&&(ifPrint'="") {
        q:(ifPrint="true")&&(printFlag="") 0
        s findPrintFlag=0,findNotPrintFlag=0
        if (printFlag'=""){
            i printFilterSings="" s findPrintFlag=1
            i notPrintFilterSings="" s findNotPrintFlag=1
            if (printFilterSings'="")&&(notPrintFilterSings'=""){ 
                for k=1:1:$l(printFlag,"-") {
                    s onePrintFlag=$p(printFlag,"-",k)
                    continue:onePrintFlag=""
                    s onePrintFlag="^"_onePrintFlag_"^"
                    if (printFilterSings'=""){
                        if (("^"_printFilterSings_"^")[onePrintFlag) s printFlagList(printFlagFilterRule)=+$g(printFlagList(printFlagFilterRule))+1
                    }
                    if (notPrintFilterSings'=""){
                        if (("^"_notPrintFilterSings_"^")'[onePrintFlag) s noPrintFlagList(notPrintFlagFilterRule)=+$g(noPrintFlagList(notPrintFlagFilterRule))+1
                    }
                }
                if (printFlagFilterRule="AND"){
                    if (+$g(printFlagList(printFlagFilterRule)))=$l(printFilterSings,"^") s findPrintFlag=1
                }else{
                    if (+$g(printFlagList(printFlagFilterRule)))>0 s findPrintFlag=1
                }
                if (notPrintFlagFilterRule="AND"){
                    if (+$g(noPrintFlagList(notPrintFlagFilterRule)))<$l(notPrintFilterSings,"^") s findNotPrintFlag=1
                }else{
                    if (+$g(noPrintFlagList(notPrintFlagFilterRule)))<1 s findNotPrintFlag=1
                }
            }
        }
        q:(ifPrint="true")&&(findPrintFlag=0) 0
        q:(ifPrint="false")&&(findNotPrintFlag=1) 0
    }
    // 处置状态
    s excutedOrderFlag=queryArgument.excutedOrderFlagGet()
    s searchDisposeStat=currentSheetSetting.GetAt("DisposeStat")
    i (oeoreSub'="") {
        // 执行记录
        s:excutedOrderFlag="" searchDisposeStat=searchDisposeStat_"^Exec^Discontinue^"
        s:(excutedOrderFlag="true") searchDisposeStat="^Exec^Discontinue^"
    }else{
        // 医嘱
        s:(excutedOrderFlag="true") searchDisposeStat="^AlreadyDeal^AlreadyStop^"
        if (excutedOrderFlag="false") {
            i searchDisposeStat["PreStopOrder" s searchDisposeStat="^NeedToDeal^NeedToStop^PreStopOrder^"
            e  s searchDisposeStat="^NeedToDeal^NeedToStop^"
        }
        if (excutedOrderFlag="") {
            i searchDisposeStat["PreStopOrder" s searchDisposeStat="^AlreadyDeal^AlreadyStop^NeedToDeal^NeedToStop^PreStopOrder^"
            e  s searchDisposeStat="^AlreadyDeal^AlreadyStop^NeedToDeal^NeedToStop^"
        }
    }
    q:(("^"_searchDisposeStat_"^")'[("^"_disposeStatCode_"^"))&&(disposeStatCode'="") 0
    
    // 医嘱状态
    s ordStatusID=filterInfo.GetAt("ordStatusID")
    s searchOrdStat=currentSheetSetting.GetAt("OrdStat")
    q:(("^"_searchOrdStat_"^")'[("^"_ordStatusID_"^"))&(ordStatusID'="") 0
    
    // 医嘱阶段
    s stage=filterInfo.GetAt("stage")
    s searchOrdStage=currentSheetSetting.GetAt("OrdStage")
    s sheetShowAnaestheAllStageOrd=currentSheetSetting.GetAt("sheetShowAnaestheAllStageOrd") //显示麻醉师所有医嘱阶段医嘱
    if (sheetShowAnaestheAllStageOrd'="Y")||(filterInfo.GetAt("AnaesthOrdFlag")'="Y"){
        q:(("^"_searchOrdStage_"^")'[("^"_stage_"^")) 0
    }
    
    // 医嘱优先级
    s oecprID=filterInfo.GetAt("oecprID")
    s searchOecpr=currentSheetSetting.GetAt("Oecpr")
    q:(("^"_searchOecpr_"^")'[("^"_oecprID_"^"))&(oecprID'="") 0
    
    // 医嘱用法 
    s phcinID=filterInfo.GetAt("phcinID")
    s searchOrdPhcin=currentSheetSetting.GetAt("OrdPhcin")
    //没有医嘱用法的不过滤
    i phcinID'="" {
        q:(("^"_searchOrdPhcin_"^")'[("^"_+phcinID_"^")) 0
    }
    
    // 医嘱分类
    s arcicID=filterInfo.GetAt("arcicID")
    s searchOrdCat=currentSheetSetting.GetAt("OrdCat")
    q:(("^"_searchOrdCat_"^")'[("^"_arcicID_"^"))&(arcicID'="") 0
     
    // 标本名称  V8.5.2起改为判断标本Id
    /*s specCode=filterInfo.GetAt("specCode")  
    s searchSpecCode=currentSheetSetting.GetAt("SpecCode")
    q:(("^"_searchSpecCode_"^")'[("^"_specCode_"^"))&(specCode'="") 0*/
    s SpecimenDR=filterInfo.GetAt("SpecimenDR")   
    s searchSpecCode=currentSheetSetting.GetAt("SpecCode")
    q:(("^"_searchSpecCode_"^")'[("^"_SpecimenDR_"^"))&(SpecimenDR'="") 0
    
    // 接受科室
    s reclocID=filterInfo.GetAt("reclocID")
    s searchRecloc=currentSheetSetting.GetAt("Recloc")
    q:(("^"_searchRecloc_"^")'[("^"_reclocID_"^"))&(reclocID'="")&(searchRecloc'="") 0
    
    s sheetOnlyShowCurRecLocOrd=currentSheetSetting.GetAt("sheetOnlyShowCurRecLocOrd") //仅显示接收科室为本科室医嘱
    q:(sheetOnlyShowCurRecLocOrd="Y")&&(reclocID'=filterInfo.GetAt("locID")) 0
    
    // 开医嘱人医护类型
    if (currentSheetSetting.GetAt("docNurFilterSubOrd")="Y"){
        s mainOrdID=$p($g(^OEORD(oeordID,"I",oeoriSub,11)),"^",39)
        if (mainOrdID'=""){
            s ctcptType=filterInfo.GetAt("ctcptType")
            s needCtcptType=queryArgument.ctcptTypeGet()
            q:(needCtcptType'="")&(ctcptType'=needCtcptType) 0
        }
    }
    q:('queryArgument.PDAFilter(oeordID,oeoriSub,oeoreSub,filterInfo,currentSheetSetting)) 0
    q 1
}

/// Description:    根据护士执行列维护的基础数据获取执行记录数据
/// Input:          oeordID，oeoriSub，oeoreSub：执行记录ID，excutedOrderFlag：筛选已执行为true、筛选未执行为false，columns：列数组
/// Return:       
/// Other:
ClassMethod InitOrderExecInfo(oeordID, oeoriSub, oeoreSub, excutedOrderFlag, columns, colorsSetting, currentSheetSetting As %ArrayOfDataTypes) As %ArrayOfDataTypes
{
    n (oeordID, oeoriSub, oeoreSub, excutedOrderFlag, columns, colorsSetting,currentSheetSetting,%session)
    s orderExecInfo=##class(%ArrayOfDataTypes).%New()
    ;;;s columnsLen=columns.Count()
    ;;;for i=1:1:columnsLen 
    ;;;{
        ;;;s column=columns.GetAt(i)
        // 如果基础数据为医嘱数据则过滤
        ;;;s execFlag=column.GetAt("execFlag")
        ;;;continue:execFlag="false"
        ;;;s key=column.GetAt("key")
        ;;;s value=##class(Nur.NIS.Service.Base.BedConfig).GetBasicDataByCode("2",key,oeordID_"||"_oeoriSub_"||"_oeoreSub)
        ;;;s value=##class(ext.util.String).EvalJSON(value)
        ;;;d orderExecInfo.SetAt(value,key)
    ;;;}
    //获取单据下医嘱附加信息
    ;;;d ..GetOrdExecAddInfoList(oeordID_"||"_oeoriSub_"||"_oeoreSub,currentSheetSetting,.orderExecInfo)
    
    // 要求执行日期 MM-DD 格式
    ;;;s sttDate=$p($g(^OEORD(oeordID,"I",oeoriSub,"X",oeoreSub)),"^",1)
    ;;;s sttDate=$zd(sttDate,3)
    ;;;s sttDate=$e(sttDate,6,15)
    ;;;d orderExecInfo.SetAt(sttDate,"sttDate")
    
    // 要求执行时间 HH:MM 格式
    ;;;s sttTime=$p($g(^OEORD(oeordID,"I",oeoriSub,"X",oeoreSub)),"^",2)
    ;;;s sttTime=$zt(sttTime,2)
    ;;;d orderExecInfo.SetAt(sttTime,"sttTime")
    
    // 要求执行日期时间
    ;;;i ('orderExecInfo.IsDefined("sttDateTime")) {
        ;;;s sttDateTime=##class(Nur.NIS.Service.OrderExcute.OrderInfo).GetSttDateTime(oeordID_"||"_oeoriSub_"||"_oeoreSub)
        ;;;d orderExecInfo.SetAt(sttDateTime,"sttDateTime")
    ;;;}
    
    // 执行记录ID
    d orderExecInfo.SetAt(oeordID_"||"_oeoriSub_"||"_oeoreSub,"ID")
    
    // 执行状态Code
    ;;;i ('orderExecInfo.IsDefined("execStatusCode")) {
        ;;;s execStatusCode=##class(Nur.NIS.Service.OrderExcute.OrderInfo).GetExecStatusCode(oeordID_"||"_oeoriSub_"||"_oeoreSub)
        ;;;d orderExecInfo.SetAt(execStatusCode,"execStatusCode")
    ;;;}
    // 打印标记
    ;;;s printFlag=$p($g(^OEORD(oeordID,"I",oeoriSub,"X",oeoreSub,"NUR")),"^",1)
    ;;;d orderExecInfo.SetAt(printFlag,"printFlag")
    
    // 发药状态
    ;;;i ('orderExecInfo.IsDefined("dspStat")) {
        ;;;s dspStat=##class(Nur.NIS.Service.OrderExcute.OrderInfo).GetDspStat(oeordID_"||"_oeoriSub_"||"_oeoreSub)
        ;;;d orderExecInfo.SetAt(dspStat,"dspStat")
    ;;;}
    ;;;s ExecStateDR= $p($g(^OEORD(oeordID,"I",oeoriSub,"X",oeoreSub)),"^",16)
    ;;;if +ExecStateDR>0 s TExecStateCode=$p(^OEC("STAT",ExecStateDR),"^",1)
    // 执行人
    ;;;s execUser=""
    ;;;if (((excutedOrderFlag="true")||(excutedOrderFlag=""))&&($g(TExecStateCode)="F")) {
        ;;;s execCTPCP=$p($g(^OEORD(oeordID,"I",oeoriSub,"X",oeoreSub)),"^",15) 
        ;;;i execCTPCP'="" s execUser=$p($g(^CTPCP(execCTPCP,1)),"^",2),execUser=##class(User.CTCareProv).GetTranByDesc("CTPCPDesc",execUser)
        
        // 执行复核人
        ;;;s execCheckUser=""
        ;;;s execChecUserDr=$p($g(^OEORD(oeordID,"I",oeoriSub,"X",oeoreSub,"NUR")),"^",32) 
        ;;;i execChecUserDr'="" s execCheckUser=$P(^SSU("SSUSR",execChecUserDr),"^",2) ,execCheckUser=##class(User.SSUser).GetTranByDesc("SSUSRName",execCheckUser)
        ;;;i execCheckUser'="" s execUser=execUser_" "_execCheckUser    
    ;;;}
    ;;;d orderExecInfo.SetAt(execUser,"execCtcpDesc")

    // 实际执行时间 MM-DD HH:mm
    ;;;s execDateTime=""
    ;;;if ((excutedOrderFlag="true")||(excutedOrderFlag=""))&&($g(TExecStateCode)="F") {
        ;;;s execDate=$p($g(^OEORD(oeordID,"I",oeoriSub,"X",oeoreSub)),"^",19)
        ;;;s execTime=$p($g(^OEORD(oeordID,"I",oeoriSub,"X",oeoreSub)),"^",20)
        // 实际执行时间改为 YYYY-MM-DD hh:mm:ss 需求号:3970675
        //s:((execDate'="")&&(execTime'="")) execDateTime=$e($zd(execDate,3),6,15)_" "_$zt(execTime,2)  
        ;;;s execDateTime=##class(Nur.NIS.Service.OrderExcute.OrderInfo).GetExecDateTime(oeordID_"||"_oeoriSub_"||"_oeoreSub)
    ;;;}
    ;;;d orderExecInfo.SetAt(execDateTime,"execDateTime")       
    
    // 获取执行次数
    ;;;i ('orderExecInfo.IsDefined("freqNo")) {
        ;;;s freqNo=##class(Nur.NIS.Service.OrderExcute.OrderInfo).GetFreqNo(oeordID_"||"_oeoriSub_"||"_oeoreSub)
        ;;;d orderExecInfo.SetAt(freqNo,"freqNo")
    ;;;}
    
    // 接收科室
    ;;;s recLoc=##class(Nur.NIS.Service.OrderExcute.OrderInfo).GetRecLocByExec(oeordID_"||"_oeoriSub_"||"_oeoreSub)
    ;;;d orderExecInfo.SetAt(recLoc,"reclocDesc")
    
    // 标本号
    ;;;i ('orderExecInfo.IsDefined("labNo")) {
        ;;;s labNo=##class(Nur.NIS.Service.OrderExcute.OrderInfo).GetLabNo(oeordID_"||"_oeoriSub)
        ;;;d orderExecInfo.SetAt(labNo,"labNo")
    ;;;}
    ;;;i ('orderExecInfo.IsDefined("filteFlagExtend")) {
        // 静配标志
        ;;;s filteFlag=..FilteFlagExtend(oeordID, oeoriSub, oeoreSub)
        ;;;d orderExecInfo.SetAt(filteFlag,"filteFlagExtend")
    ;;;}
    // 类别
    ;;;s ordTyp=..GetDrugFlag(oeordID, oeoriSub)
    ;;;d orderExecInfo.SetAt(ordTyp,"ordTyp")
    
    // 新检查申请单-部位信息
    s examPartInfo=..GetExamPartInfo(oeordID, oeoriSub, oeoreSub, excutedOrderFlag)
    i examPartInfo'="" d
    .d orderExecInfo.SetAt(examPartInfo,"examInfo")
    
    // 是否手动绑定用法医嘱
    ;;;s execID=oeordID_"||"_oeoriSub_"||"_oeoreSub
    ;;;s execAttachFlag=..IfExecAttachOrd(execID)
    ;;;i execAttachFlag'="" d orderExecInfo.SetAt(execAttachFlag,"execAttachFlag")
    
    // 获取组合查询数据
    ;;;s cmDspState=##class(web.DHCCLCom).GetDispensingStat(oeordID_"||"_oeoriSub_"||"_oeoreSub,"N")
    ;;;d orderExecInfo.SetAt(cmDspState,"cmDspState")
    // 获取组合查询数据
    ;;;d orderExecInfo.SetAt($p($g(^OEORD(oeordID,"I",oeoriSub,1)),"^",2),"cmArcim")
    ;;;d orderExecInfo.SetAt($p($g(^OEORD(oeordID,"I",oeoriSub,2)),"^",7),"cmOrdPhcin")
    
    ;;;s cmDeviceType=##class(Nur.NIS.Service.OrderExcute.OrderInfo).GetExecDeviceType(oeordID_"||"_oeoriSub_"||"_oeoreSub)
    ;;;d orderExecInfo.SetAt(cmDeviceType,"cmDeviceType")
    q orderExecInfo
}

/// Description:    根据护士执行列维护的基础数据获取医嘱数据
/// Input:          oeordID，oeoriSub：医嘱ID，subOrder：是否是子医嘱数据，columns：列数组
/// Return:       
/// Other:
ClassMethod InitOrderInfo(oeordID, oeoriSub, subOrder, columns As %ListOfDataTypes, colorsSetting As %ListOfDataTypes, currentSheetSetting As %ArrayOfDataTypes) As %ArrayOfDataTypes
{
    n (oeordID, oeoriSub, subOrder, columns, colorsSetting,currentSheetSetting,%session)
    s orderInfo=##class(%ArrayOfDataTypes).%New()
    ;;;s columnsLen=columns.Count()
    ;;;for i=1:1:columnsLen 
    ;;;{
        ;;;s column=columns.GetAt(i)
        //如果基础数据为执行记录数据则过滤
        ;;;s execFlag=column.GetAt("execFlag")
        ;;;continue:execFlag="true"
        //如果当前为获取子医嘱数据且列维护为不显示子医嘱则过滤
        ;;;s multiply=column.GetAt("multiply")
        ;;;continue:(subOrder="Y")&&(multiply="false")
        ;;;s key=column.GetAt("key")
        ;;;s value=##class(Nur.NIS.Service.Base.BedConfig).GetBasicDataByCode("1",key,oeordID_"||"_oeoriSub)
        ;;;s value=##class(ext.util.String).EvalJSON(value)
        ;;;d orderInfo.SetAt(value,key)
    ;;;}
    //获取单据下医嘱附加信息
    ;;;d ..GetOrdAddInfoList(oeordID_"||"_oeoriSub,subOrder,currentSheetSetting,.orderInfo)
    
    //医嘱背景色
    ;;;s backgroundColor=..GetBackgroundColor(oeordID, oeoriSub, subOrder,colorsSetting)
    ;;;d orderInfo.SetAt(backgroundColor,"backgroundColor")
    
    ;;;i ('orderInfo.IsDefined("PRESCNOFlag")) {
        ;;;s prescNO=##class(Nur.NIS.Service.OrderExcute.OrderInfo).GetOrderPRESCNO(oeordID_"||"_oeoriSub)
        ;;;d orderInfo.SetAt($g(prescNO),"PRESCNOFlag")
    ;;;}
    /*s prescNO=$p(^OEORD(oeordID,"I",oeoriSub,1),"^",14)
    i prescNO="" d
    .s prescRowid=$o(^PAQUE1(0,"DHCPAQue","AddLongOrderID",oeordID_"||"_oeoriSub,0))
    .i prescRowid'="" s prescNO=$p(^PAQUE1(prescRowid),"^",14)
    s ifShowPrescFlag="N"
    i prescNO'="" d ifShowPrescNo
    i ifShowPrescFlag="Y" d orderInfo.SetAt($g(prescNO),"PRESCNO")*/
    
    d orderInfo.SetAt(oeordID_"||"_oeoriSub,"ID")
    ;;;s episodeID=+^OEORD(oeordID)
    ;;;d orderInfo.SetAt(episodeID,"episodeID")
    ;;;s patientID=$p($g(^PAADM(episodeID)),"^",1)
    ;;;d orderInfo.SetAt(patientID,"patientID")
    ;;;s mrAdmID=$P(^PAADM(episodeID),"^",61)
    ;;;d orderInfo.SetAt(mrAdmID,"mradm")
    //获取医嘱信息显示需要的必要信息
    ;;;s orderInfo=##class(Nur.NIS.Service.Base.Order).GetArcimDescShowNecessaryInfo(oeordID, oeoriSub, .orderInfo)
    i (orderInfo.GetAt("labNo")="") {
        s labNo=##class(Nur.NIS.Service.OrderExcute.OrderInfo).GetLabNo(oeordID_"||"_oeoriSub)
        d orderInfo.SetAt(labNo,"labNo")
    }
    //修复 检验单* 列未维护显示医嘱状态时,选中医嘱打印条码时提示没有选择满足打印条件的医嘱
    ;;;if (orderInfo.GetAt("ordStatDesc")=""){
        ;;;s ordStatDesc=##class(Nur.NIS.Service.OrderExcute.OrderInfo).GetOecprDesc(oeordID_"||"_oeoriSub)
        ;;;d orderInfo.SetAt(ordStatDesc,"ordStatDesc")
    ;;;}
    
    // 获取组合查询数据
    // 医嘱项
    ;;;s cmArcim=$p($g(^OEORD(oeordID,"I",oeoriSub,1)),"^",2)
    ;;;d orderInfo.SetAt(cmArcim,"cmArcim")
    // 医嘱子分类
    ;;;s arcicID=$p($g(^ARCIM(+cmArcim,$p(cmArcim,"||",2),1)),"^",10)
    ;;;s cmOrdCat=""
    ;;;i arcicID'="" s arcicID=+arcicID,cmOrdCat=$p($g(^ARC("IC",arcicID)),"^",8)
    ;;;d orderInfo.SetAt(arcicID,"cmOrdCat")
    // 用法
    ;;;s cmOrdPhcin=$p($g(^OEORD(oeordID,"I",oeoriSub,2)),"^",7) 
    ;;;d orderInfo.SetAt(cmOrdPhcin,"cmOrdPhcin")
    // 接受科室
    ;;;s cmRecLoc=$p($g(^OEORD(oeordID,"I",oeoriSub,3)),"^",6)
    ;;;d orderInfo.SetAt(cmRecLoc,"cmRecLoc")
    // 加急
    ;;;s cmEmergency=""
    ;;;i (orderInfo.GetAt("emergency")="Y") {
        ;;;s cmEmergency="emergency"    
    ;;;}
    ;;;d orderInfo.SetAt(cmEmergency,"cmEmergency")
    q orderInfo
ifShowPrescNo
    s ordid=""
    f  s ordid=$o(^OEORD(0,"PrescNo",prescNO,ordid)) q:ordid=""  d
    .s subid="" f  s subid=$o(^OEORD(0,"PrescNo",prescNO,ordid,subid)) q:(subid="")!(ifShowPrescFlag="Y")  d
    ..s arcimID=$p($g(^OEORD(ordid,"I",subid,1)),"^",2)
    ..q:arcimID=""
    ..s ifShowPrescFlag="N"
    ..i ##class(websys.Conversions).IsValidMethodName("web.DHCPHACOM.ComInterface.FaceOutToDHC","CkIfCyByOeori") d
    ...s ifShowPrescFlag=##class(web.DHCPHACOM.ComInterface.FaceOutToDHC).CkIfCyByOeori(ordid_"||"_subid)
    q
}

/// Description:    获取非需处理、非变化医嘱单及非当前单据外的其他单据的Code和护士执行筛选条件
/// Input:          groupID：安全组ID，locID：科室ID，hospID：医院ID，currentSheetCode：当前单据code,applyBusiness:适用业务(默认护士执行)
/// Return:       
/// Other:          w ##class(Nur.JSON).Encode(##class(Nur.MNISV3.Service.QueryOrder).GetSheetsSetting("23","114",2))
ClassMethod GetSheetsSetting(groupID, locID, hospID, currentSheetCode, applyBusiness = "NurE") As %ListOfDataTypes
{
    n (groupID,locID,hospID,currentSheetCode,applyBusiness,%session)
    s sheetsSetting=##class(%ListOfDataTypes).%New()
    s EGHospID=##class(web.DHCBL.BDP.BDPMappingHOSP).GetDefHospIdByTableName("Nur_IP_ExecuteGroup",hospID,"")
    // 获取安全组配置
    /*s rowId=$o(^CF.NUR.NIS.ExecuteGroupI("TypeItem",EGHospID," 1"," "_groupID, ""))
    // 获取科室配置
    s locRowId=$o(^CF.NUR.NIS.ExecuteGroupI("TypeItem",EGHospID," 2"," "_locID, ""))*/
    // 获取安全组配置
    s rowId=$o(^CF.NUR.NIS.ExecuteGroupI("TypeItem",EGHospID," 1"," "_groupID," "_$zcvt(applyBusiness,"U"), ""))
    // 获取科室配置
    s locRowId=$o(^CF.NUR.NIS.ExecuteGroupI("TypeItem",EGHospID," 2"," "_locID," "_$zcvt(applyBusiness,"U"), ""))
    
    // 如果科室配置不为空则取科室配置
    i locRowId'="" s rowId=locRowId
    i (rowId'="") {
        s subRowId=""
        for
        {
            s subRowId=$o(^CF.NUR.NIS.ExecuteGroupSubD(rowId,subRowId))
            q:subRowId=""
            s data=$g(^CF.NUR.NIS.ExecuteGroupSubD(rowId,subRowId))
            s sheetId=$lg(data,2)
            continue:sheetId=""
            s sheetData=$g(^CF.NUR.NIS.NurseSheetSetD(sheetId))
            s sheetCode=$lg(sheetData,2)
            //continue:(currentSheetCode=sheetCode)||(sheetCode="DefaultSee")||(sheetCode="BGYZD")
            #dim sheetSetting As %ArrayOfDataTypes
            s sheetSetting=..GetSheetSetting(sheetCode,hospID)
            d sheetSetting.SetAt(sheetCode,"Code")
            s sheetName=$lg(sheetData,3)
            d sheetSetting.SetAt(sheetName,"Name")
            d sheetsSetting.Insert(sheetSetting)
        }
    }
    q sheetsSetting
}

/// Description:    获取单据的护士执行筛选条件
/// Input:          sheetCode：单据code，hospID：医院ID
/// Return:       
/// Other:          w ##class(Nur.JSON).Encode(##class(Nur.MNISV3.Service.QueryOrder).GetSheetSetting("DefaultSee","2"))
ClassMethod GetSheetSetting(sheetCode, hospID) As %ArrayOfDataTypes
{
    
    n (sheetCode, hospID, %session)
    s sheetSetting=##class(%ArrayOfDataTypes).%New()
    s defHospID=##class(web.DHCBL.BDP.BDPMappingHOSP).GetDefHospIdByTableName("Nur_IP_ExecuteSheet",hospID,"")
    s rowID=$o(^CF.NUR.NIS.NurseSheetSetI("Code",defHospID," "_$zcvt(sheetCode,"U"),""))
    i (rowID'="") {
        s data=$g(^CF.NUR.NIS.NurseSheetSetD(rowID))
        s DisposeStat=$lg(data,7)
        s Oecpr=$lg(data,8)
        s OrdCat=$lg(data,9)
        s OrdStat=$lg(data,10)
        s OrdPhcin=$lg(data,11)
        s OrdStage=$lg(data,12)
        s SpecCode=$lg(data,13)
        s Recloc=$lg(data,14)
        //单据需过滤医嘱项ID串
        s FilterArcims=$lg(data,17)
        //绑定医嘱明细显示标志(配置后鼠标悬浮执行记录显示病区绑定医嘱维护数据)
        s BindOrdDetailFlag=$lg(data,27)
        //已打印筛选打印标记
        s printFilterSings=$lg(data,34)
        s printFilterSingCodes=""
        if (printFilterSings'="") {
            for j=1:1:$l(printFilterSings,"^") {
                s printSingId=$p(printFilterSings,"^",j)
                continue:printSingId=""
                s printSingCode=$lg(^CF.NUR.NIS.SheetPrtSignSetD(printSingId),2)
                continue:printSingCode=""
                i printFilterSingCodes="" s printFilterSingCodes=printSingCode
                else  s printFilterSingCodes=printFilterSingCodes_"^"_printSingCode
            }
            //s:printFilterSingCodes'="" printFilterSingCodes="^"_printFilterSingCodes_"^"
        }
        //未打印筛选打印标记
        s notPrintFilterSings=$lg(data,36) 
        s notPrintFilterSingCodes=""
        if (notPrintFilterSings'="") {
            for j=1:1:$l(notPrintFilterSings,"^") {
                s printSingId=$p(notPrintFilterSings,"^",j)
                continue:printSingId=""
                s printSingCode=$lg(^CF.NUR.NIS.SheetPrtSignSetD(printSingId),2)
                continue:printSingCode=""
                i notPrintFilterSingCodes="" s notPrintFilterSingCodes=printSingCode
                else  s notPrintFilterSingCodes=notPrintFilterSingCodes_"^"_printSingCode
            }
            //s:notPrintFilterSingCodes'="" notPrintFilterSingCodes="^"_notPrintFilterSingCodes_"^"
        }
        //已打印筛选-多个打印标记筛选规则
        s printFlagFilterRule=$lg(data,40)
        i printFlagFilterRule="" s printFlagFilterRule="OR"
        s notPrintFlagFilterRule=$lg(data,41)
        i notPrintFlagFilterRule="" s notPrintFlagFilterRule="OR"
        s filterPreOrd=$lg(data,42)
        s docNurFilterSubOrd=$lg(data,43)
        s sheetOnlyShowCurRecLocOrd=$lg(data,45)
        s sheetShowAnaestheAllStageOrd=$lg(data,46)
        d sheetSetting.SetAt(sheetCode,"sheetCode")
        d sheetSetting.SetAt(DisposeStat,"DisposeStat")
        d sheetSetting.SetAt(Oecpr,"Oecpr")
        d sheetSetting.SetAt(OrdCat,"OrdCat")
        d sheetSetting.SetAt(OrdStat,"OrdStat")
        d sheetSetting.SetAt(OrdPhcin,"OrdPhcin")
        d sheetSetting.SetAt(OrdStage,"OrdStage")
        d sheetSetting.SetAt(SpecCode,"SpecCode")
        d sheetSetting.SetAt(Recloc,"Recloc")
        d sheetSetting.SetAt(FilterArcims,"FilterArcims")
        d sheetSetting.SetAt(BindOrdDetailFlag,"BindOrdDetailFlag")
        d sheetSetting.SetAt(printFilterSingCodes,"printFilterSings")
        d sheetSetting.SetAt(notPrintFilterSingCodes,"notPrintFilterSings")
        d sheetSetting.SetAt(rowID,"sheetRowId")
        d sheetSetting.SetAt(printFlagFilterRule,"printFlagFilterRule")
        d sheetSetting.SetAt(notPrintFlagFilterRule,"notPrintFlagFilterRule")
        d sheetSetting.SetAt(filterPreOrd,"filterPreOrd")
        d sheetSetting.SetAt(docNurFilterSubOrd,"docNurFilterSubOrd")
        d sheetSetting.SetAt(..GetSheetTypeBySheetCode(sheetCode, hospID),"sheetType")
        d sheetSetting.SetAt(sheetOnlyShowCurRecLocOrd,"sheetOnlyShowCurRecLocOrd")
        d sheetSetting.SetAt(sheetShowAnaestheAllStageOrd,"sheetShowAnaestheAllStageOrd")
        //单据-医嘱附加信息配置
        s ordAddInfoList=##class(%ListOfDataTypes).%New()
        k ordAddInfoArr
        s addSub=""
        for {
            s addSub=$o(^CF.NUR.NIS.NurseSheetSetD(rowID,"OrdAddtionSub",addSub)) q:addSub=""
            s addData=$g(^CF.NUR.NIS.NurseSheetSetD(rowID,"OrdAddtionSub",addSub))
            s itemActive=$lg(addData,7)
            continue:itemActive'="Y"
            s itemSeqNo=$lg(addData,2)
            s itemName=$lg(addData,3)
            s itemBasic=$lg(addData,4)
            continue:itemBasic=""
            continue:$ISVALIDNUM(itemBasic)=0
            s itemCode=$lg(^CT.NUR.NIS.NurseBasicDataD(itemBasic),2)
            continue:itemCode=""
            s itemBackgroundColor=$lg(addData,5)
            s itemFontColor=$lg(addData,6)
            s itemShowMode=$lg(addData,8)
            i itemSeqNo="" s itemSort="9999"
            e  s itemSort=itemSeqNo
            s subOrdShow=$lg(addData,9)
            s addInfo=##class(%ArrayOfDataTypes).%New()
            d addInfo.SetAt(itemName,"itemName")
            d addInfo.SetAt(itemCode,"itemCode")
            d addInfo.SetAt(itemBasic,"itemBasic")
            d addInfo.SetAt(itemBackgroundColor,"itemBackgroundColor")
            d addInfo.SetAt(itemFontColor,"itemFontColor")
            d addInfo.SetAt(itemShowMode,"itemShowMode")
            d addInfo.SetAt(subOrdShow,"itemSubOrdShow")
            s ordAddInfoArr(itemSort,addSub)=addInfo
        }
        s itemSort=""
        for {
            s itemSort=$o(ordAddInfoArr(itemSort)) q:itemSort=""
            s itemSub=""
            for {
                s itemSub=$o(ordAddInfoArr(itemSort,itemSub)) q:itemSub=""
                d ordAddInfoList.Insert($g(ordAddInfoArr(itemSort,itemSub)))
            }
        }
        d sheetSetting.SetAt(ordAddInfoList,"ordAddInfoList")
    }
    s hospID=##class(web.DHCBL.BDP.BDPMappingHOSP).GetDefHospIdByTableName("Nur_IP_ExecuteConfig",hospID,"")
    s rowID=$o(^CF.NUR.NIS.ExecuteConfigI("HospId",hospID,""))
    s config=##class(%ArrayOfDataTypes).%New()
    i (rowID'="") {
        s data=$g(^CF.NUR.NIS.ExecuteConfigD(rowID))
        // 过滤治疗类医嘱
        s filterCureApplyOrd=$lg(data,50)
        d sheetSetting.SetAt(filterCureApplyOrd,"filterCureApplyOrd")
    }
    q sheetSetting
}

/// Description:    过滤非本科本病区下的医护人员医嘱
/// Input:          wardId：病区ID，needCtcptType：医护人员类型(DOCTOR、NURSE)
///                 ctcpLocIdStr，oeoriId：医嘱ID
/// Return:       
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).OrdWardLinkDoc("40","","","7751||26")
ClassMethod OrdWardLinkDoc(wardId, needCtcptType, ctcpLocIdStr, oeoriId) As %String
{
    n (wardId, needCtcptType, ctcpLocIdStr, oeoriId)
    s oeordId=+oeoriId,oeoriSub=$p(oeoriId,"||",2)
    s wardLinkDoc="N"
    s EpisodeID=+^OEORD(oeordId)
    q:EpisodeID=0 -1
    q:wardId="" -2
    s patWardId=$p($g(^PAADM(EpisodeID)),"^",70)
    q:patWardId="" -3
    i ctcpLocIdStr="" s ctcpLocIdStr=##Class(web.DHCCLCom).GetWardLinkLocId(wardId,"")
    q:ctcpLocIdStr="" -4 //病区未关联科室
    s wardCtlocId=$p($g(^PAWARD(wardId)),"^",5)
    i (needCtcptType'="DOCTOR") s ctcpLocIdStr=wardCtlocId_"^"_ctcpLocIdStr
    s userId=$P($G(^OEORD(oeordId,"I",oeoriSub,7)),"^",1)
    q:userId="" "R" 
    s admLocId=$p(^PAADM(EpisodeID),"^",4)
    q:admLocId="" -5
    s ctcpId=$P($g(^SSU("SSUSR",userId)),"^",14)
    q:ctcpId="" -6
    s ctcptId=$P($G(^CTPCP(ctcpId,1)),"^",4)  ;CTPCP_CarPrvTp_DR
    q:ctcptId="" -7
    s ctcptType=$P($g(^CT("CPT",ctcptId)),"^",4)  ;CT_CarPrvTp
    q:(needCtcptType'="")&(ctcptType'=needCtcptType) -8
    s docLocId=""
    f  s docLocId=$o(^RB("RES",0,"CTPCP",ctcpId,docLocId)) q:docLocId=""  d 
    .s RESRowId=0,inValidDateFlag=0
    .f  s RESRowId=$o(^RB("RES",0,"CTPCP",ctcpId,docLocId,RESRowId)) q:(RESRowId="")||(inValidDateFlag=1)  d 
    ..s dateFrom=$p($g(^RB("RES",RESRowId)),"^",22)
    ..s dateTo=$p($g(^RB("RES",RESRowId)),"^",23)
    ..i (dateFrom>+$h)||((dateTo'="")&&(dateTo<+$h)) s inValidDateFlag=1
    .q:inValidDateFlag=1
    .i ("^"_ctcpLocIdStr_"^")[("^"_docLocId_"^") s wardLinkDoc="Y" 
    q wardLinkDoc
}

/// Description:    过滤非本科本病区下的医护人员医嘱
/// Input:          locId：科室ID，needCtcptType：医护人员类型(DOCTOR、NURSE)
///                 oeoriId：医嘱ID，filterPreOrd(Y:过滤预住院医嘱 N:不过滤预住院医嘱)
/// Return:         
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).OrdLocLinkWard
ClassMethod OrdLocLinkWard(locId, needCtcptType, oeoriId, filterPreOrd = "N") As %String
{
    n (locId,needCtcptType,oeoriId,filterPreOrd)
    s oeordId=+oeoriId,oeoriSub=$p(oeoriId,"||",2)
    q:oeoriId="" -1
    s EpisodeID=+^OEORD(oeordId)
    q:EpisodeID=0 -2
    q:locId="" -3
    s locLinkDoc="N"
    s ctcpLocIdStr=##Class(web.DHCCLCom).GetLinkLocId(locId)
    i ctcpLocIdStr'="" s ctcpLocIdStr=ctcpLocIdStr_"^"
    s ctcpLocIdStr=ctcpLocIdStr_locId
    s userId=$P($G(^OEORD(oeordId,"I",oeoriSub,7)),"^",1)
    q:userId="" "R"
    s userDeptId=$P($G(^OEORD(oeordId,"I",oeoriSub,7)),"^",2)
    q:userDeptId="" "R"     
    s ctcpId=$P($g(^SSU("SSUSR",userId)),"^",14)
    q:ctcpId="" -6
    s ctcptId=$P($g(^CTPCP(ctcpId,1)),"^",4)  ;CTPCP_CarPrvTp_DR
    q:ctcptId="" -7
    s ctcptType=$P($g(^CT("CPT",ctcptId)),"^",4)  ;CT_CarPrvTp
    q:(needCtcptType'="")&(ctcptType'=needCtcptType) -8
    s OEORIPreInPatFlag=$p($g(^OEORD(oeordId,"I",oeoriSub,"DHC")),"^",67) //预住院医嘱,患者是预住院状态时开立的医嘱
    q:(OEORIPreInPatFlag="Y")&&(filterPreOrd="N") "Y"
    s docLocId=""
    i ("^"_ctcpLocIdStr_"^")[("^"_userDeptId_"^") s locLinkDoc="Y"
    i locLinkDoc'="Y" d
    .s ordLocLinkWardStr=""
    .d getOtherWard
    .i ("^"_ordLocLinkWardStr_"^")[("^"_locId_"^")  s locLinkDoc="Y" //其他允许科室
    .i $p(^CTLOC(userDeptId),"^",86)="Y"   s locLinkDoc="Y"  //开单科室无收治限制
    q locLinkDoc

getOtherWard  //获取科室配置的其他允许收治病区
    s wardr=0
    f  s wardr=$O(^CTLOC(userDeptId,"LINKWARD",0,"Ward",wardr)) Q:wardr=""  d
    .s wardLocID=$p($g(^PAWARD(+wardr)),"^",5)
    .s ordLocLinkWardStr=ordLocLinkWardStr_"^"_wardLocID
    q
}

/// Description:    获取静配标志(2022.06.17 为区分首日不走静配的执行记录,执行记录判断是否为静配可通过打包表dhc_oedispensing中的接收科室字段DSP_RecDep_DR判断)
/// Input：          oeordID，oeoriSub：医嘱ID
/// Return：     1:存在 0:不存在
/// Other           w ##class(Nur.MNISV3.Service.QueryOrder).FilteFlagExtend
ClassMethod FilteFlagExtend(oeordID, oeoriSub, oeoreSub = "")
{
    n (oeordID, oeoriSub, oeoreSub,%session) 
    s flag="",recLoc="",NurIPDosingRecLoc=""
    if (oeoreSub'=""){
        s DSPRowId=$o(^DHCOEDISQTY(0,"OEORE",oeordID_"||"_oeoriSub_"||"_oeoreSub,""))
        if (DSPRowId'=""){
            s recLoc=$p($g(^DHCOEDISQTY(DSPRowId)),"^",24)
        }
    }else{
        s recLoc=$p($g(^OEORD(oeordID,"I",oeoriSub,3)),"^",6)
    }
    s NurIPDosingRecLoc=##Class(DHCDoc.DHCDocConfig.DocConfig).GetDosingRecLocStr() //##class(web.DHCDocConfig).GetConfigNode("IPDosingRecLoc","")
    s NurIPDosingRecLoc="^"_NurIPDosingRecLoc_"^" //静配中心
    i ((recLoc'="")&&(NurIPDosingRecLoc[("^"_recLoc_"^"))) s flag="JP" 
    q flag
}

/// Description:    获取药品标志
/// Input：          oeordID，oeoriSub：医嘱ID
/// Return：     
/// Other           w ##class(Nur.MNISV3.Service.QueryOrder).GetDrugFlag
ClassMethod GetDrugFlag(oeordID, oeoriSub) As %String
{
    n (oeordID, oeoriSub)
    s ordTyp=""
    s arcimDr=$p(^OEORD(oeordID,"I",oeoriSub,1),"^",2)
    s itemCatDr=$P($G(^ARCIM(+arcimDr,$p(arcimDr,"||",2),1)),"^",10)
    s ordTyp=$P(^ARC("IC",itemCatDr),"^",7)
    i ordTyp'="R" d
    .s relationMainOrd=$p($g(^OEORD(oeordID,"I",oeoriSub,11)),"^",39)
    .i relationMainOrd'="" d
    ..s otherSub="" f  s otherSub=$o(^OEORDi(0,"OEORI",oeordID,relationMainOrd,otherSub)) q:((otherSub="")!(ordTyp="R"))  d
    ...s mainArcimDr=$p(^OEORD(+relationMainOrd,"I",otherSub,1),"^",2)
    ...s itemCatDr=$P($G(^ARCIM(+mainArcimDr,$p(mainArcimDr,"||",2),1)),"^",10)
    ...s ordTyp=$P(^ARC("IC",itemCatDr),"^",7)
    q ordTyp
}

/// Description:    根据执行记录取检查部位信息
/// Input：          oeordID，oeoriSub，oeoreSub：执行记录ID，excutedOrderFlag：
/// Return：     
/// Other           w ##class(Nur.MNISV3.Service.QueryOrder).GetExamPartInfo()
ClassMethod GetExamPartInfo(oeordID, oeoriSub, oeoreSub, excutedOrderFlag) As %ArrayOfDataTypes
{
    n (oeordID, oeoriSub, oeoreSub, excutedOrderFlag, %session)
    if (##class(websys.Conversions).IsValidMethodName("web.DHCAPPInterface","GetExaReqID")=0)
    {
        q ""
    }
    s examInfoObj=##class(%ArrayOfDataTypes).%New()
    s ret=""
    s ordID=oeordID_"||"_oeoriSub   
    s arPartID=##Class(web.DHCAPPInterface).GetExaReqID(ordID)  
    q:arPartID="" examInfoObj
    s oeoreID=oeordID_"||"_oeoriSub_"||"_oeoreSub
    s commFlag="N"  
    s aprID=$O(^DHCAPREPTA(0,"IndexOrdExec",oeoreID,""))
    q:$g(aprID)="" examInfoObj
    s ARTIType=$p(^DHCAPREPTA(aprID),"^",3)
    s:ARTIType'="P" commFlag="Y"
    s arcimID =$p($g(^OEORD(oeordID,"I",oeoriSub,1)),"^",2)
    i arcimID'="" {
        s arcimDesc= $P($G(^ARCIM(+arcimID,$p(arcimID,"||",2),1)),"^",2)
        s arcimDesc=##class(User.ARCItmMast).GetTranByDesc("ARCIMDesc",arcimDesc)
    }
    s DispDesc=##Class(web.DHCAPPExaReportQuery).GetRepDisp(arPartID) ///后处理
    i DispDesc'="" s arcimDesc=arcimDesc_" + "_DispDesc
    
    s TrID=$o(^DHCAPREPTA(0,"IndexOrdExec",oeordID_"||"_oeoriSub_"||"_oeoreSub,""))
    if (TrID){
        s TarID=$p(^DHCAPREPTA(TrID),"^",5)      /// 收费项ID
        s TarDesc=$p(^DHCTARI(TarID),"^",2)      /// 收费项描述
        s TarDesc=##class(User.DHCTarItem).GetTranByDesc("TARIDesc",TarDesc)
        d examInfoObj.SetAt(TarDesc,"TarDesc")
    }
    s partInfos = ##Class(web.DHCAPPInterface).GetExaReqPartNur(ordID)
    s partsLen = $L(partInfos,"^")
    s:arPartID'="" partTarFlag=##Class(web.DHCAPPExaReport).GetPartTarFlag(arPartID)            
    f partIndex=1:1:partsLen {
        s partInfo=$p(partInfos,"^",partIndex)
        s partID = $p(partInfo,"@",1)
        s partDesc = $p(partInfo,"@",2)
        s type="E" 
        i excutedOrderFlag="true" s type=""
        s execInfos=##Class(web.DHCAPPInterface).GetExaReqOrdExNur(ordID,partID,type)       
        s execLen = $L(execInfos,"^")
        f execIndex=1:1:execLen {
            s execID=$P(execInfos,"^",execIndex)
            i execID=oeoreID d  
            .s ARChildSub=$o(^DHCAPREP(0,"Part",partID,+arPartID,$p(arPartID,"||",2),""))
            .s:ARChildSub'="" partRemark=$p($g(^DHCAPREP(+arPartID,"AR",$p(arPartID,"||",2),"PA",ARChildSub)),"^",8)
            .s ret=partID_"^"_partDesc_"^"_$g(partTarFlag)_"^"_commFlag
            .d examInfoObj.SetAt(partID,"partID")
            .d examInfoObj.SetAt(partDesc,"partDesc")
            .d examInfoObj.SetAt($g(partRemark),"partRemark")
            .d examInfoObj.SetAt(partTarFlag,"partTarFlag")
            .d examInfoObj.SetAt(arcimDesc,"arcimDesc")
            .d examInfoObj.SetAt(commFlag,"examComm")
            q:ret'=""
        }
        q:ret'=""
    }   
    i ret="" {
        s exFlag=0
        i excutedOrderFlag="true" s exFlag=1
        f partExecIndex=1:1:partsLen {
            s partInfo=$p(partInfos,"^",partExecIndex)
            s partID = $p(partInfo,"@",1)
            s partDesc = $p(partInfo,"@",2)
            s partExecFlag=##class(web.DHCAPPInterface).GetPartExecFlag(arPartID,partID)        
            i partExecFlag=exFlag {
                s ARChildSub=$o(^DHCAPREP(0,"Part",partID,+arPartID,$p(arPartID,"||",2),""))
                s:ARChildSub'="" partRemark=$p($g(^DHCAPREP(+arPartID,"AR",$p(arPartID,"||",2),"PA",ARChildSub)),"^",8)
                s ret=partID_"^"_partDesc_"^"_$g(partTarFlag)_"^"_commFlag
                d examInfoObj.SetAt(partID,"partID")
                d examInfoObj.SetAt(partDesc,"partDesc")
                d examInfoObj.SetAt($g(partRemark),"partRemark")
                d examInfoObj.SetAt(partTarFlag,"partTarFlag")
                d examInfoObj.SetAt(arcimDesc,"arcimDesc")
                d examInfoObj.SetAt(commFlag,"examComm")
            }
            q:ret'=""
        }       
    }
    q examInfoObj
}

/// Description:    判断执行记录是否绑定了用法关联医嘱
/// Input：          execID：执行记录ID
/// Return：     
/// Other           w ##class(Nur.MNISV3.Service.QueryOrder).IfExecAttachOrd
ClassMethod IfExecAttachOrd(execID)
{
    n (execID, %session)
    s attachFlag=""
    s execAttachID=""
    f  s execAttachID=$O(^Nur.ExecAttachAricmI("OEOREID"," "_execID,execAttachID)) q:(execAttachID="")!(attachFlag="Y")  d
    .s orderID=$listget(^Nur.ExecAttachAricmD(execAttachID),4)
    .s orordID=+orderID,oeordSub=$p(orderID,"||",2)
    .q:(orordID="")!(oeordSub="")
    .s ordStatusId=$P($g(^OEORD(orordID,"I",oeordSub,1)),"^",13)
    .s ordStat=$p($g(^OEC("OSTAT",ordStatusId)),"^",1)
    .q:(ordStat="C")!(ordStat="D")!(ordStat="U")
    .s attachFlag="Y"
    q attachFlag
}

/// Description:    测试闭环
ClassMethod getOrdCloseLoopInfo(oeoreID)
{
    n (oeoreID)
    // 测试
    s ordLoopList =##class(%ArrayOfDataTypes).%New()
    s ret=##class(%ListOfDataTypes).%New()
    f i=1:1:3 {
        s item=##class(%ArrayOfDataTypes).%New()
        d item.SetAt("类型","workType")
        d item.SetAt("人","workUser")
        d item.SetAt("日期","loopDate")
        d item.SetAt("时间","loopTime")
        d ret.Insert(item)
    }
    d ordLoopList.SetAt(ret,"ordLoopList")
    q ordLoopList
}

/// Description:    获取处置状态代码对应的描述及颜色
/// Input:          医院Id
/// Return:       
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).GetDisposeStateInfo(2)
ClassMethod GetDisposeStateInfo(hospId) As %String
{
    n (hospId, %session)
    s disposeState=##class(%ArrayOfDataTypes).%New()
    s DRCHospId=##class(web.DHCBL.BDP.BDPMappingHOSP).GetDefHospIdByTableName("Nur_IP_DataRelationConfig",hospId,"")
    s rowID=""
    for
    {
        s rowID=$o(^CT.NUR.NIS.DataRelationConfigI("Hosp",DRCHospId,rowID))
        q:rowID=""
        s data=$g(^CT.NUR.NIS.DataRelationConfigD(rowID))
        s delFlag=$lg(data,7)
        continue:delFlag="1"
        s type=$lg(data,5)
        // 过滤非处置状态
        continue:type'="3"
        s desc=$lg(data,2)
        s desc=##class(CT.NUR.NIS.DataRelationConfig).GetTranByDesc("DRCDesc",desc)
        s code=$lg(data,3)
        s color=##class(Nur.NIS.Service.Base.ColorSetting).GetColorByCode(code,hospId)
        s disposeStateItem=##class(%ArrayOfDataTypes).%New()
        d disposeStateItem.SetAt(desc,"desc")
        d disposeStateItem.SetAt(color,"color")
        d disposeState.SetAt(disposeStateItem,code)
    }
    q disposeState
    //q ##class(Nur.JSON).Encode(disposeState)
}

/// Description:    获取单据对应的列信息
/// Input:          医院Id,单据Code
/// Return:       
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).GetSheetColumns()
ClassMethod GetSheetColumns(sheetCode, hospId) As %ListOfDataTypes
{
    n (sheetCode, hospId, %session)
    s columns=##class(%ListOfDataTypes).%New()
    s hospId=##class(web.DHCBL.BDP.BDPMappingHOSP).GetDefHospIdByTableName("Nur_IP_ExecuteSheet",hospId,"")
    s sheetId=$o(^CF.NUR.NIS.NurseSheetSetI("Code",hospId," "_$zcvt(sheetCode,"U"),""))
    i (sheetId'="") {
        s subRowID=""
        for
        {
            s subRowID=$o(^CF.NUR.NIS.ExecButtonColumnD(sheetId,subRowID))
            q:subRowID=""
            s data=^CF.NUR.NIS.ExecButtonColumnD(sheetId,subRowID)
            s itemType=$lg(data,2)
            continue:itemType'="C"
            s serialId=$lg(data,4)
            s itemId=$lg(data,3)
            s sort(serialId)=itemId
        }
        s sortId=""
        for
        {
            s sortId=$o(sort(sortId))
            q:sortId=""
            s itemId=sort(sortId)
            s itemData=$g(^CF.NUR.NIS.ColumnConfigD(itemId))
            s title=$lg(itemData,2)
            s title=##class(CF.NUR.NIS.ColumnConfig).GetTranByDesc("CCDesc",title)
            // 护理基础数据RowID
            s NBDRowID=$lg(itemData,3)
            continue:NBDRowID=""
            s NBDData=$g(^CT.NUR.NIS.NurseBasicDataD(NBDRowID))
            s NBDCode=$lg(NBDData,2)
            s NBDType=$lg(NBDData,3)
            s NBDName=$lg(NBDData,4)
            s filter="false"
            i NBDName'="" s filter="true"
            // 是否是执行记录数据
            s execFlag=$s(NBDType="2":"true",NBDType="1":"false",1:"false")
            i execFlag="true" s filter="false"
            s NBDExpression=$lg(NBDData,6)
            s width=$lg(itemData,4)
            s:(NBDCode="arcimDesc")&&(width<300) width=300
            s showSubOrd=$lg(itemData,5)
            s showSubOrd=$s(showSubOrd="Y":"true",1:"false")
            s column=##class(%ArrayOfDataTypes).%New()
            d column.SetAt(title,"title")
            d column.SetAt(NBDCode,"key")
            d column.SetAt(filter,"filter")
            d column.SetAt(execFlag,"execFlag")
            d column.SetAt(NBDExpression,"funCode")
            d column.SetAt(width,"width")
            d column.SetAt(showSubOrd,"multiply")
            d columns.Insert(column)
        }
    }
    q columns
}

/// Description:    获取单据下按钮
/// Input:          医院Id,单据Code,执行标记
/// Return:       
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).GetSheetButtons()
ClassMethod GetSheetButtons(hospId, sheetCode, excuteOrderFlag) As %String
{
    n (hospId, sheetCode, excuteOrderFlag, %session)
    s buttons=##class(%ListOfDataTypes).%New()
    s hospId=##class(web.DHCBL.BDP.BDPMappingHOSP).GetDefHospIdByTableName("Nur_IP_ExecuteSheet",hospId,"")
    s sheetId=$o(^CF.NUR.NIS.NurseSheetSetI("Code",hospId," "_$zcvt(sheetCode,"U"),""))
    i (sheetId'="") {
        s subRowID=""
        for
        {
            s subRowID=$o(^CF.NUR.NIS.ExecButtonColumnD(sheetId,subRowID))
            q:subRowID=""
            s data=^CF.NUR.NIS.ExecButtonColumnD(sheetId,subRowID)
            s itemType=$lg(data,2)
            continue:itemType'="B"
            s serialId=$lg(data,4)
            s itemId=$lg(data,3)
            s formWorkId=$lg(data,5)
            s sort(serialId)=$lb(itemId,formWorkId)
        }
        s sortId=""
        for
        {
            s sortId=$o(sort(sortId))
            q:sortId=""
            s itemId=$lg(sort(sortId),1)
            s formWorkId=$lg(sort(sortId),2)
            s itemData=$g(^CF.NUR.NIS.ButtonConfigD(itemId))
            s itemDesc=$lg(itemData,2)
            s itemName=$lg(itemData,3)
            continue:itemName=""
            s itemName=##class(CF.NUR.NIS.ButtonConfig).GetTranByDesc("BCName",itemName)
            s itemCode=$lg(itemData,4)
            // 已执行下过滤[执行医嘱][处理医嘱][停止执行]按钮
            continue:(excuteOrderFlag="true")&&(($zcvt(itemCode,"U")="EXCUTEORDER")||($zcvt(itemCode,"U")="SEEORDER")||($zcvt(itemCode,"U")="STOPEXCUTEORDER"))
            // 未执行/默认下过滤[撤销执行][撤销处理]按钮
            continue:(excuteOrderFlag="false")&&(($zcvt(itemCode,"U")="CANCELORDER")||($zcvt(itemCode,"U")="CANCELSEEORDER"))
            s itemFunction=$lg(itemData,5)
            s itemShowWindow=$lg(itemData,7)
            s itemShowWindow=$s(itemShowWindow="Y":"true",1:"false")
            s itemSign=$lg(itemData,8)
            s itemSign=$s(itemSign="Y":"true",1:"false")
            s itemPrintFlag=""
            s isSingleCheck=""
            i formWorkId'="" {
                s formWork=$g(^CF.NUR.NIS.SheetPrtSetD(formWorkId))
                s printFlagId=$lg(formWork,21)
                s isSingleCheck=$s($lg(formWork,28)=2:"Y",1:"N")
                s:printFlagId'="" itemPrintFlag=$lg($g(^CF.NUR.NIS.SheetPrtSignSetD(printFlagId)),2)
            }
            s button=##class(%ArrayOfDataTypes).%New()
            d button.SetAt(itemDesc,"desc")
            d button.SetAt(itemName,"name")
            d button.SetAt(itemCode,"code")
            d button.SetAt(itemFunction,"jsFunction")
            d button.SetAt(itemShowWindow,"showWindow")
            d button.SetAt(itemSign,"itemSign")
            d button.SetAt(itemPrintFlag,"printFlag")
            d button.SetAt(isSingleCheck,"isSingleCheck")
            d button.SetAt(formWorkId,"formWorkId")
            d buttons.Insert(button)
        }
    }
    q ##class(Nur.JSON).Encode(buttons)
}

/// Description:    获取执行配置
/// Input:          医院Id
/// Return:       
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).GetExecConfig
ClassMethod GetExecConfig(hospId) As %String
{
    n (hospId, %session)
    s hospId=##class(web.DHCBL.BDP.BDPMappingHOSP).GetDefHospIdByTableName("Nur_IP_ExecuteConfig",hospId,"")
    s rowID=$o(^CF.NUR.NIS.ExecuteConfigI("HospId",hospId,""))
    
    s config=##class(%ArrayOfDataTypes).%New()
    i (rowID'="") {
        s data=$g(^CF.NUR.NIS.ExecuteConfigD(rowID))
        // 医嘱执行默认显示时间(0:当前时间,1:要求执行时间)
        s execDefaultDT=$lg(data,2)
        s:execDefaultDT="" execDefaultDT=0
        // 允许修改医嘱执行默认显示时间
        s editeDefaultDT=$lg(data,3)
        // 双签支持本科医生
        s permitDosSign=$lg(data,22)    
        //处理医嘱显示备注输入框
        s seeOrdShowNotes=$lg(data,29)
        //处理医嘱接收备注必填
        s seeReceiveRequired=$lg(data,30)
        //处理医嘱拒绝备注必填
        s seeRefuseRequired=$lg(data,31)
        //皮试备注必填
        s skinTestNotesRequired=$lg(data,40)
    }
    d config.SetAt($g(execDefaultDT),"execDefaultDT")
    d config.SetAt($g(editeDefaultDT),"editeDefaultDT")
    d config.SetAt($g(permitDosSign),"permitDosSign")
    d config.SetAt($g(seeOrdShowNotes),"seeOrdShowNotes")
    d config.SetAt($g(seeReceiveRequired),"seeReceiveRequired")
    d config.SetAt($g(seeRefuseRequired),"seeRefuseRequired")
    d config.SetAt($g(skinTestNotesRequired),"skinTestNotesRequired")
    q ##class(Nur.JSON).Encode(config)
}

/// Description:    获取查询配置
/// Input:          医院Id
/// Return:       
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).GetQueryConfig
ClassMethod GetQueryConfig(hospId, sheetCode = "") As %String
{
    n (hospId, sheetCode,%session)
    s locID=$g(%session.Data("LOGON.CTLOCID"))
    s transSetting=##class(Nur.NIS.Service.OrderExcute.QueryOrder).GetTransSetting(hospId)
    s hospId=##class(web.DHCBL.BDP.BDPMappingHOSP).GetDefHospIdByTableName("Nur_IP_ExecuteConfig",hospId,"")
    s rowID=$o(^CF.NUR.NIS.ExecuteConfigI("HospId",hospId,""))
    
    s config=##class(%ArrayOfDataTypes).%New()
    i (rowID'="") {
        s data=$g(^CF.NUR.NIS.ExecuteConfigD(rowID))
        // 医嘱执行默认显示时间(0:当前时间,1:要求执行时间,2:空)
#;      s execDefaultDT=$lg(data,2)
#;      s:execDefaultDT="" execDefaultDT=0
        // 允许修改医嘱执行默认显示时间
#;      s editeDefaultDT=$lg(data,3)
#;      s editeDefaultDT=$s(editeDefaultDT="Y":"true",1:"false")
        // 查询开始日期
        s startDate=+$lg(data,12)
        s startDate=##class(websys.Conversions).DateLogicalToHtml(+$h+startDate)    
        // 查询开始时间
        s startTime=$lg(data,13)
        s:startTime="" startTime="00:00"
        // 查询结束日期
        s endDate=+$lg(data,14)
        s endDate=##class(websys.Conversions).DateLogicalToHtml(+$h+endDate) 
        // 查询结束时间
        s endTime=$lg(data,15)
        s:endTime="" endTime="23:59"
        // 查询病人数上限
        s maxPatNum=$lg(data,16)
        
        // 执行次数提示
        s execTimes=$lg(data,17)
        s execTimes=$s(execTimes="Y":"true",1:"false")
        // 发药状态提示
        s dspStat=$lg(data,18)
        s dspStat=$s(dspStat="Y":"true",1:"false")
        // 打印标记提示
        s printFlag=$lg(data,19)
        s printFlag=$s(printFlag="Y":"true",1:"false")
        // CA标记提示
        s caShowFlag=$lg(data,24)
        s caShowFlag=$s(caShowFlag="Y":"true",1:"false")
        //静配标记
        s jpShowFlag=$lg(data,25)
        s jpShowFlag=$s(jpShowFlag="Y":"true",1:"false")
        //点击任意位置勾选整行
        s clickAutoCheckRow=$lg(data,46)
        // 执行和置皮试结果顺序 0:先执行后置皮试结果 1:置皮试结果同步执行
        s skinOrdExecSequence=$lg(data,41)
        // 选中行背景色
        s checkRowBackColor=$lg(data,47)
        // 切换单据保留模糊检索条件
        s chgSheetKeepSearchCondition=$lg(data,48)
        // 切换单据保留模糊检索内容
        s chgSheetKeepSearchContent=$lg(data,49)
        //患者列表切换患者自动查询医嘱
        s patChangeAutoSearchOrd=$lg(data,52)
        //查询时间默认
        s defaultSearchTime=$lg(data,60)
        i defaultSearchTime="" s defaultSearchTime=0
    }
    if (sheetCode'=""){
        s sheetId=$o(^CF.NUR.NIS.NurseSheetSetI("Code",hospId," "_$zcvt(sheetCode,"U"),""))
        if (sheetId'="") {
            s sheetOtherConfig=$g(^CF.NUR.NIS.NurseSheetSetD(sheetId))
            // 查询开始日期
            s startDate=$lg(sheetOtherConfig,18)
            s startDate=##class(websys.Conversions).DateLogicalToHtml(+$h+startDate) 
            // 查询开始时间
            s startTime=$lg(sheetOtherConfig,19)
            s:startTime="" startTime="00:00"
            // 查询结束日期
            s endDate=$lg(sheetOtherConfig,20)
            s endDate=##class(websys.Conversions).DateLogicalToHtml(+$h+endDate) 
            // 查询结束时间
            s endTime=$lg(sheetOtherConfig,21)
            s:endTime="" endTime="23:59"
            // 执行次数提示
            s execTimes=$lg(sheetOtherConfig,22)
            s execTimes=$s(execTimes="Y":"true",1:"false")
            // 发药状态提示
            s dspStat=$lg(sheetOtherConfig,23)
            s dspStat=$s(dspStat="Y":"true",1:"false")
            // 打印标记提示
            s printFlag=$lg(sheetOtherConfig,24)
            s printFlag=$s(printFlag="Y":"true",1:"false")
            // CA标记提示
            s caShowFlag=$lg(sheetOtherConfig,25)
            s caShowFlag=$s(caShowFlag="Y":"true",1:"false")
            //静配标记
            s jpShowFlag=$lg(sheetOtherConfig,26)
            s jpShowFlag=$s(jpShowFlag="Y":"true",1:"false")
            //绑定医嘱明细提示
            s bindOrdDetailFlag=$lg(sheetOtherConfig,27)
            s bindOrdDetailFlag=$s(bindOrdDetailFlag="Y":"true",1:"false")
            ////护士执行默认展示模式 Ord:医嘱模式 OrdExec:执行记录
            s displayDefaultMode=$lg(sheetOtherConfig,28)
            if (sheetCode="DefaultSee")||(sheetCode="BGYZD") s displayDefaultMode="Ord"
            //医嘱模式时,执行记录详情是否默认展开
            s ordExecFoldFlag=$lg(sheetOtherConfig,29) 
            s ordExecFoldFlag=$s(ordExecFoldFlag="Y":"true",1:"false")
            if (sheetCode="DefaultSee")||(sheetCode="BGYZD") s ordExecFoldFlag="false"
            //日期快速切换筛选
            s dateSwitchFilterFlag=$lg(sheetOtherConfig,30) 
            s dateSwitchFilterFlag=$s(dateSwitchFilterFlag="Y":"true",1:"false")
            //今日新开、新停筛选
            s ordChangeFilterFlag=$lg(sheetOtherConfig,31) 
            s ordChangeFilterFlag=$s(ordChangeFilterFlag="Y":"true",1:"false")
            //未确认、已确认筛选
            s ordConfirmFilterFlag=$lg(sheetOtherConfig,32) 
            s ordConfirmFilterFlag=$s(ordConfirmFilterFlag="Y":"true",1:"false")
            //已打印筛选
            s printFilterFlag=$lg(sheetOtherConfig,33)
            s printFilterFlag=$s(printFilterFlag="Y":"true",1:"false")
            if (printFilterFlag="false") s printFlag=""
            //未打印筛选
            s notPrintFilterFlag=$lg(sheetOtherConfig,35) 
            s notPrintFilterFlag=$s(notPrintFilterFlag="Y":"true",1:"false")
            //未执行(未处理)筛选
            s notExecutedFilterFlag=$lg(sheetOtherConfig,37) 
            s notExecutedFilterFlag=$s(notExecutedFilterFlag="Y":"true",1:"false")
            //长期医嘱默认时间范围
            s defaultTimeByPrior=$lg(sheetOtherConfig,50)
            // 查询开始日期
            s longStartDate=$lg(sheetOtherConfig,51)
            s longStartDate=##class(websys.Conversions).DateLogicalToHtml(+$h+longStartDate) 
            // 查询开始时间
            s longStartTime=$lg(sheetOtherConfig,52)
            // 查询结束日期
            s longEndDate=$lg(sheetOtherConfig,53)
            s longEndDate=##class(websys.Conversions).DateLogicalToHtml(+$h+longEndDate) 
            // 查询结束时间
            s longEndTime=$lg(sheetOtherConfig,54)
            //临时医嘱默认时间范围
            // 查询开始日期
            s tempStartDate=$lg(sheetOtherConfig,55)
            s tempStartDate=##class(websys.Conversions).DateLogicalToHtml(+$h+tempStartDate) 
            // 查询开始时间
            s tempStartTime=$lg(sheetOtherConfig,56)
            // 查询结束日期
            s tempEndDate=$lg(sheetOtherConfig,57)
            s tempEndDate=##class(websys.Conversions).DateLogicalToHtml(+$h+tempEndDate) 
            // 查询结束时间
            s tempEndTime=$lg(sheetOtherConfig,58)
            
            //科室查询时间默认配置
            if (locID'=""){
                s locDefaultTimeId =$o(^CF.NUR.NIS.ExecLocDefTimeSetI("LocId",sheetId,locID,""))
                if (locDefaultTimeId'=""){
                    s locDefaultTimeConfig=$g(^CF.NUR.NIS.ExecLocDefTimeSetD(locDefaultTimeId))
                    // 查询开始日期
                    s startDate=$lg(locDefaultTimeConfig,4)
                    s startDate=##class(websys.Conversions).DateLogicalToHtml(+$h+startDate) 
                    // 查询开始时间
                    s startTime=$lg(locDefaultTimeConfig,5)
                    // 查询结束日期
                    s endDate=$lg(locDefaultTimeConfig,6)
                    s endDate=##class(websys.Conversions).DateLogicalToHtml(+$h+endDate) 
                    // 查询结束时间
                    s endTime=$lg(locDefaultTimeConfig,7)
                    
                    //长期医嘱默认时间范围
                    s defaultTimeByPrior=$lg(locDefaultTimeConfig,8)
                    if (defaultTimeByPrior="Y"){
                        // 查询开始日期
                        s longStartDate=$lg(locDefaultTimeConfig,9)
                        s longStartDate=##class(websys.Conversions).DateLogicalToHtml(+$h+longStartDate) 
                        // 查询开始时间
                        s longStartTime=$lg(locDefaultTimeConfig,10)
                        // 查询结束日期
                        s longEndDate=$lg(locDefaultTimeConfig,11)
                        s longEndDate=##class(websys.Conversions).DateLogicalToHtml(+$h+longEndDate) 
                        // 查询结束时间
                        s longEndTime=$lg(locDefaultTimeConfig,12)
                        //临时医嘱默认时间范围
                        // 查询开始日期
                        s tempStartDate=$lg(locDefaultTimeConfig,135)
                        s tempStartDate=##class(websys.Conversions).DateLogicalToHtml(+$h+tempStartDate) 
                        // 查询开始时间
                        s tempStartTime=$lg(locDefaultTimeConfig,14)
                        // 查询结束日期
                        s tempEndDate=$lg(locDefaultTimeConfig,15)
                        s tempEndDate=##class(websys.Conversions).DateLogicalToHtml(+$h+tempEndDate) 
                        // 查询结束时间
                        s tempEndTime=$lg(locDefaultTimeConfig,16)
                    }
                }
            }
            
        }
    }
#;  d config.SetAt(execDefaultDT,"execDefaultDT")
#;  d config.SetAt(editeDefaultDT,"editeDefaultDT")
    s printSetting=$p(transSetting,"^",4)
    s printSetting=$s(printSetting="N":"true",1:"false")
    d config.SetAt($g(startDate),"startDate")
    d config.SetAt($g(startTime),"startTime")
    d config.SetAt($g(endDate),"endDate")
    d config.SetAt($g(endTime),"endTime")
    d config.SetAt($g(maxPatNum),"maxPatNum")
    d config.SetAt($g(execTimes),"execTimes")
    d config.SetAt($g(dspStat),"dspStat")
    d config.SetAt($g(printFlag),"printFlag")
    d config.SetAt($g(printSetting),"printSetting")
    d config.SetAt($g(caShowFlag),"caShowFlag")
    d config.SetAt($g(jpShowFlag),"jpShowFlag")
    
    d config.SetAt($g(bindOrdDetailFlag),"bindOrdDetailFlag")
    d config.SetAt($g(displayDefaultMode),"displayDefaultMode")
    d config.SetAt($g(ordExecFoldFlag),"ordExecFoldFlag")
    d config.SetAt($g(dateSwitchFilterFlag),"dateSwitchFilterFlag")
    d config.SetAt($g(ordChangeFilterFlag),"ordChangeFilterFlag")
    d config.SetAt($g(ordConfirmFilterFlag),"ordConfirmFilterFlag")
    d config.SetAt($g(printFilterFlag),"printFilterFlag")
    d config.SetAt($g(notPrintFilterFlag),"notPrintFilterFlag")
    d config.SetAt($g(notExecutedFilterFlag),"notExecutedFilterFlag")
    d config.SetAt($g(clickAutoCheckRow),"clickAutoCheckRow")
    d config.SetAt($g(checkRowBackColor),"checkRowBackColor")
    d config.SetAt($g(chgSheetKeepSearchCondition),"chgSheetKeepSearchCondition")
    d config.SetAt($g(chgSheetKeepSearchContent),"chgSheetKeepSearchContent")
    d config.SetAt($g(skinOrdExecSequence),"skinOrdExecSequence")
    d config.SetAt($g(patChangeAutoSearchOrd),"patChangeAutoSearchOrd")
    d config.SetAt($g(defaultSearchTime),"defaultSearchTime")
    d config.SetAt($g(defaultTimeByPrior),"defaultTimeByPrior")
    d config.SetAt($g(longStartDate),"longStartDate")
    d config.SetAt($g(longStartTime),"longStartTime")
    d config.SetAt($g(longEndDate),"longEndDate")
    d config.SetAt($g(longEndTime),"longEndTime")
    d config.SetAt($g(tempStartDate),"tempStartDate")
    d config.SetAt($g(tempStartTime),"tempStartTime")
    d config.SetAt($g(tempEndDate),"tempEndDate")
    d config.SetAt($g(tempEndTime),"tempEndTime")
    
    q ##class(Nur.JSON).Encode(config)
}

/// Description:    获取打印标记描述
/// Input:          hospId：医院Id
/// Return:       
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).GetPrintFlagDesc
ClassMethod GetPrintFlagDesc(hospId) As %String
{
    n (hospId, %session)
    s desc=##class(%ArrayOfDataTypes).%New()
    /*s rowid=""
    for
    {
        s rowid=$o(^CF.NUR.NIS.ButtonConfigD(rowid))   
        q:rowid=""
        s data=$g(^CF.NUR.NIS.ButtonConfigD(rowid))
        continue:data=""
        s printFlag =$lg(data,9)
        continue:printFlag=""
        s printFlagDesc =$lg(data,10)
        s printFlagDesc=##class(CF.NUR.NIS.ButtonConfig).GetTranByDesc("BCPrintFlagDesc",printFlagDesc)
        d desc.SetAt(printFlagDesc,printFlag)
    }*/
    //2022.4.27 取护士打印设置-打印标记维护
    s SPSSID=""
    for{
        s SPSSID=$o(^CF.NUR.NIS.SheetPrtSignSetD(SPSSID))   
        q:SPSSID=""
        s data=$g(^CF.NUR.NIS.SheetPrtSignSetD(SPSSID))
        continue:data=""
        s SPSSCode=$lg(data,2) //代码 
        s SPSSDesc=$lg(data,3) //名称
        s SPSSDesc=##class(CF.NUR.NIS.SheetPrtSignSet).GetTranByDesc("SPSSDesc",SPSSDesc)
        d desc.SetAt(SPSSDesc,SPSSCode)
    }
    q desc
}

/// Description:    判断成组医嘱是否需要双签
/// Input:          oeordID, oeoriSub：医嘱ID，hospID：医院ID
/// Return:       
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).IsDoubleSignOrderGroup
ClassMethod IsDoubleSignOrderGroup(oeordID, oeoriSub, hospID) As %Boolean
{
    n (oeordID, oeoriSub, hospID)
    s doubleSignFlag=..IsDoubleSignOrder(oeordID, oeoriSub, hospID)
    i doubleSignFlag'="Y" {
        s maiOrdID=oeordID_"||"_oeoriSub
        s child=0
        for
        {
            s child=$O(^OEORDi(0,"OEORI",oeordID,maiOrdID,child))
            q:(child="")||(doubleSignFlag="Y")
            s doubleSignFlag=..IsDoubleSignOrder(oeordID, child, hospID)
        }
    }
    q doubleSignFlag
}

/// Description:    判断医嘱是否需要双签
/// Input:          oeordID, oeoriSub：医嘱ID，hospID：医院ID
/// Return:         Y：需要双签、N：不需要
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).IsDoubleSignOrder(10048663,57,2)
ClassMethod IsDoubleSignOrder(oeordID, oeoriSub, hospID) As %Boolean
{
    n (oeordID, oeoriSub, hospID, %session)
    s hospId=##class(web.DHCBL.BDP.BDPMappingHOSP).GetDefHospIdByTableName("Nur_IP_DoubleSign",hospID,"")
    // 是否是高危药
    s highRiskFlag=##class(Nur.NIS.Service.Base.Order).GetHighRiskFlag(oeordID, oeoriSub)
    // 是否是化疗药
    s chemDrugFlag=##class(Nur.NIS.Service.Base.Order).GetChemDrugFlag(oeordID, oeoriSub)
    // 医嘱项
    s arcimID=$p($g(^OEORD(oeordID,"I",oeoriSub,1)),"^",2)
    // 医嘱子类
    s arcicID=$p($g(^ARCIM(+arcimID,$p(arcimID,"||",2),1)),"^",10)
    // 医嘱大类
    s orcatID=""
    i arcicID'="" s arcicID=+arcicID,orcatID=$p($g(^ARC("IC",arcicID)),"^",8)
    // 医嘱用法
    s phcinID=$p($g(^OEORD(oeordID,"I",oeoriSub,2)),"^",7) 
    
    s doubleSignFlag="N"
    s rowID=0
    for
    {
        s rowID=$o(^CF.NUR.NIS.DoubleSignI("HospId",hospId,rowID))  
        q:(rowID="")||(doubleSignFlag="Y")
        s data=$g(^CF.NUR.NIS.DoubleSignD(rowID))
        s type=$lg(data,3)
        s value=$lg(data,4)
        s filterFlag=..FilterDoubleSign(type, value, highRiskFlag, chemDrugFlag, arcimID, arcicID, phcinID)
        continue:filterFlag="N"
        s subType=$lg(data,5)
        i (subType'="") {
            s subValue=$lg(data,6)
            s subFilterFlag=..FilterDoubleSign(subType, subValue, highRiskFlag, chemDrugFlag, arcimID, arcicID, phcinID)
            continue:subFilterFlag="N"
        }
        s doubleSignFlag="Y"
    }
    q doubleSignFlag
}

/// Description:    判断医嘱是否满足双签规则
/// Input:          type：双签条件类型，value：值，highRiskFlag：是否高危药，chemDrugFlag：是否化疗药，arcimID：医嘱项arcicID：医嘱子类，phcinID：用法
/// Return:       
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).FilterDoubleSign
ClassMethod FilterDoubleSign(type, value, highRiskFlag, chemDrugFlag, arcimID, arcicID, phcinID) As %Boolean
{
    n (type, value, highRiskFlag, chemDrugFlag, arcimID, arcicID, phcinID)
    i (type="0") {
        // 医嘱子分类
        i (("^"_value_"^")[("^"_arcicID_"^"))&&(arcicID'="")&&(value'="") q "Y"
    }elseif (type="1"){
        // 医嘱用法
        i (("^"_value_"^")[("^"_phcinID_"^"))&&(phcinID'="")&&(value'="") q "Y"
    }elseif (type="2"){
        // 药品信息
        i ((value["H")&&(highRiskFlag="Y"))||((value["C")&&(chemDrugFlag="Y")) q "Y"
    }elseif (type="3"){
        // 医嘱项
        i (("^"_value_"^")[("^"_arcimID_"^"))&&(arcimID'="")&&(value'="") q "Y"
    }
    q "N"
}

/// Description:    判断是否存在未处理的医嘱（需处理统计）
/// Input:          episodeID：就诊号 ，groupID：安全组ID，hospID：医院ID，wardID：病区ID，locID：科室ID
/// Return:         1：存在、0：不存在
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).IfExitNeedSeeOrder("91","C","23","2","21","114")
ClassMethod IfExitNeedSeeOrder(episodeID, groupID, hospID, wardID, locID, ifUrgent = "N")
{
    n (episodeID, groupID, hospID, wardID, locID, ifUrgent,%session)
    i episodeID="91" s ^temp("IfExitNeedSeeOrder")=$lb(episodeID, groupID, hospID, wardID, locID,ifUrgent)
    i locID'="" s locType=$p(^CTLOC(locID),"^",13)
        
    s deliveryRommID=##class(Nur.IP.Delivery).getDeliveryRoomID(episodeID)
    s ifDeliveryRoom=0
    s:deliveryRommID=locID ifDeliveryRoom=1
    s admVisitStatus=$p(^PAADM(episodeID),"^",20)
    
    
    s queryArgument=##class(OrderParam).%New()
    d queryArgument.groupIDSet(groupID)
    d queryArgument.hospIDSet(hospID)
    d queryArgument.wardIDSet(wardID)
    d queryArgument.locIDSet(locID)
    d queryArgument.ctcptTypeSet("DOCTOR")
    d queryArgument.createOrderFlagSet("false")
    d queryArgument.excutedOrderFlagSet("false")
    d queryArgument.ifPrintSet("false")
    d queryArgument.longOrderFlagSet("false")
    d queryArgument.tempOrderFlagSet("false")
    d queryArgument.newCreateFlagSet("false")
    d queryArgument.newDisconFlagSet("false")
    
    s sheetSetting=..GetSheetSetting("DefaultSee", hospID)
    
    s oeordID=$o(^OEORD(0,"Adm",episodeID,0)) 
    q:oeordID="" 0
    // 需处理下未处理医嘱
    s oeoriSub=0
    s ret=0
    for
    {
        s oeoriSub=$O(^OEORDi(0,"SeeType","U",oeordID,oeoriSub))
        q:(oeoriSub="")||(ret=1)
        // 过滤子医嘱(先判断主医嘱是否满足过滤条件)
        s ordSeqID=$p($g(^OEORD(oeordID,"I",oeoriSub,11)),"^",39)
        continue:ordSeqID'=""
        s ordStatID=$p($g(^OEORD(oeordID,"I",oeoriSub,1)),"^",13)
        continue:ordStatID=""
        s OEORINotifyClinician = $p($G(^OEORD(oeordID,"I",oeoriSub,11)),"^",55)
        continue:(ifUrgent="Y")&&(OEORINotifyClinician'="Y")
        s ret=..GetNeedSeeOrder(oeordID,oeoriSub,queryArgument,ifDeliveryRoom, admVisitStatus,sheetSetting)
    }
    q:ret=1 1
    // 停止需处理医嘱且SeeType不为U的医嘱
    s stopSateDr=$O(^OEC("OSTAT",0,"Code","D",""))
    s ordCatDr=""
    for
    {
        s ordCatDr=$O(^OEORDi(0,"StatStDtTm1",oeordID,ordCatDr)) 
        q:(ordCatDr="")||(ret=1)
        s stDate=""
        for
        {
            s stDate=$O(^OEORDi(0,"StatStDtTm1",oeordID,ordCatDr,stopSateDr,stDate))
            q:(stDate="")||(ret=1)
            s stTime=""
            for
            {
                s stTime=$O(^OEORDi(0,"StatStDtTm1",oeordID,ordCatDr,stopSateDr,stDate,stTime)) 
                q:(stTime="")||(ret=1)
                s oeoriSub=0 
                for
                {
                    s oeoriSub=$O(^OEORDi(0,"StatStDtTm1",oeordID,ordCatDr,stopSateDr,stDate,stTime,oeoriSub)) 
                    q:(oeoriSub="")||(ret=1)
                    s seeOrdType=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",7)
                    // 过滤SeeType为U的医嘱
                    continue:seeOrdType="U"
                    // 过滤子医嘱
                    s ordSeqID=$p($g(^OEORD(oeordID,"I",oeoriSub,11)),"^",39)
                    continue:ordSeqID'=""
                    s ordStatID=$p($g(^OEORD(oeordID,"I",oeoriSub,1)),"^",13)
                    continue:ordStatID=""
                    s OEORINotifyClinician = $p($G(^OEORD(oeordID,"I",oeoriSub,11)),"^",55)
                    continue:(ifUrgent="Y")&&(OEORINotifyClinician'="Y")
                    s ret=..GetNeedSeeOrder(oeordID,oeoriSub,queryArgument,ifDeliveryRoom, admVisitStatus,sheetSetting) 
                }
            }
        }
    }
    q ret
}

/// Description:    判断是否存在未处理的医嘱
/// Input:          oeordID, oeoriSub, queryArgument , ifDeliveryRoom, admVisitStatus, sheetSetting
/// Return:         1：存在、0：不存在
/// Other:
ClassMethod GetNeedSeeOrder(oeordID, oeoriSub, queryArgument As OrderParam, ifDeliveryRoom, admVisitStatus, sheetSetting As %ArrayOfDataTypes)
{
    n (oeordID, oeoriSub, queryArgument, ifDeliveryRoom, admVisitStatus, sheetSetting, %session)

    s wardID=queryArgument.wardIDGet()
    s ctcptType=queryArgument.ctcptTypeGet()
    s locID=queryArgument.locIDGet()
    s locType=queryArgument.locTypeGet()
    
    s curWardLinkDocFlag=..OrdWardLinkDoc(wardID, ctcptType, "", oeordID_"||"_oeoriSub)
    s curLocLinkDocFlag=..OrdLocLinkWard(locID, ctcptType, oeordID_"||"_oeoriSub,sheetSetting.GetAt("filterPreOrd"))
        
    //下医嘱科室
    s ordDep=$p($g(^OEORD(oeordID,"I",oeoriSub,7)),"^",2)
    s ordLocType=""
    i ordDep'="" s ordLocType=$p(^CTLOC(ordDep),"^",13)
        
    // 医嘱是否为病区关联科室申请的会诊医嘱
    s ifConsultOrd=##class(Nur.IP.DrugAudit).IfConsultOrd(locID, oeordID, oeoriSub) 
        
    // 获取医嘱阶段
    s stage=$p($g(^OEORD(oeordID,"I",oeoriSub,"DHC")),"^",8)
    // 过滤非本科本病区下的医护人员医嘱
    q:(wardID'="")&&(curWardLinkDocFlag'="Y")&&(locType="OP")&&(admVisitStatus'="P")&&(ifDeliveryRoom=0)&&(ifConsultOrd="N")&(stage'="SZ")&(stage'="SQ") 0
    q:(curLocLinkDocFlag'="Y")&&(locType'="OP")&&(admVisitStatus'="P")&&(ifDeliveryRoom=0)&&(ifConsultOrd="N") 0
    // 如果当前病区为产房，则过滤掉非本科室医生所下的非产中医嘱
    q:(ifDeliveryRoom=1)&&(curLocLinkDocFlag'="Y")&&(stage'="CZ") 0

    s disposeStatCode=##class(Nur.NIS.Service.Base.Order).GetOrderDisposeStatCode(oeordID, oeoriSub)

    // 获取用于过滤的医嘱信息
    s filterInfo=..InitFilterInfo(oeordID, oeoriSub, "")
    d filterInfo.SetAt(disposeStatCode, "disposeStatCode")
    d filterInfo.SetAt(locID, "locID")
    // 过滤医嘱
    s filterFlag=..FilterOrder(oeordID, oeoriSub, "", filterInfo, queryArgument, sheetSetting)
    q:filterFlag=0 0
    q 1
}

/// Description:    获取全部电脑执行原因
/// Input:          医院Id
/// Return:       
/// Other:          d ##class(%ResultSet).RunQuery("Nur.MNISV3.Service.QueryOrder","GetAllPCExecuteReason")
Query GetAllPCExecuteReason() As websys.Query(ROWSPEC = "ID:%String:hidden,Desc:%String:原因描述,Code:%String:代码")
{
}

ClassMethod GetAllPCExecuteReasonExecute(ByRef qHandle As %Binary) As %Status
{
    s repid=$i(^CacheTemp)
    s ind=1
    s rowid=0
    s curDate=+$h
    for
    {
        s rowid=$o(^OEC("ASCR",rowid))   
        q:rowid=""
        s data=$g(^OEC("ASCR",rowid))
        continue:data=""
        s PDAExcuteReason=$p(data,"^",4)
        continue:PDAExcuteReason'="Y"
        s dateFrom=$p(data,"^",5)
        s dateTo=$p(data,"^",6)
        continue:((dateFrom'="")&&(curDate<dateFrom))||((dateTo'="")&&(curDate>dateTo))
        s reasonCode=$p(data,"^",1)
        s reasonDesc=$p(data,"^",2)
        s reasonDesc=##class(User.OECAdminStatusChReason).GetTranByDesc("ASCRDesc",reasonDesc)
        d OutPutEvent
    }
    s qHandle=$lb(0,repid,0)
    q $$$OK

OutPutEvent
    s Data=$lb(rowid,reasonDesc,reasonCode)
    s ^CacheTemp(repid,ind)=Data
    s ind=ind+1
    q
}

/// Description:    获取转科护士执行配置
/// Input:          医院Id
/// Return:       
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).GetTransSetting(2)
ClassMethod GetTransSetting(hospId)
{
    n (hospId)
    s hospId=##class(Nur.NIS.Common.Utils).GetHospitalID("Nur_IP_NeedCareOrderSet",hospId)
    s setting=$g(^DHCDishChargeSet("Disch","dischNurExcute",hospId))
    q setting
}

/// Description:    获取单个患者所有当日新停、当日新开医嘱
/// Input:          episodeID：当前患者就诊号，sheetCode：单据Code(BHYZD)
///                 queryArgument：查询参数对象，ifDeliveryRoom：当前是否是产房(1:是产房、0:不是产房)
///                 admVisitStatus：患者状态，columns：需处理的列数组
///                 isCurrentSheet：当前单据是否为前端选中单据(1:是、0:不是)，orderObject：记录其他单据是否有医嘱的对象
///                 ordersData：前端选中单据医嘱数据，labData：记录同处置状态、同标本号合管医嘱
/// Return:       
/// Other:  
ClassMethod GetBHYZDOrders(episodeID, patIndex, sheetCode, queryArgument As OrderParam, ifDeliveryRoom, admVisitStatus, columns As %ListOfDataTypes, isCurrentSheet, orderObject As %ArrayOfDataTypes, ordersData, labData, colorsSetting As %ListOfDataTypes) As %String
{
    n (episodeID, patIndex, sheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns, isCurrentSheet, orderObject, ordersData, labData, colorsSetting,%session)

    s excutedOrderFlag=queryArgument.excutedOrderFlagGet()
    s newDisconFlag=queryArgument.newDisconFlagGet()
    s newCreateFlag=queryArgument.newCreateFlagGet()
    
    s oeordID=$o(^OEORD(0,"Adm",episodeID,0)) 
    q:oeordID="" 0
    s hospID=queryArgument.hospIDGet()
    ;;;q:..filterSearch(isCurrentSheet,sheetCode,orderObject) 0
    // 获取当前单据的过滤条件
    s currentSheetSetting=..GetSheetSetting(sheetCode, hospID)
    s oeoriSub=0
     if (excutedOrderFlag'="true") {
        s stopSateDr=$O(^OEC("OSTAT",0,"Code","D",""))
        Q:stopSateDr="" 0
        for{
            s oeoriSub=$O(^OEORDi(0,"SeeType","U",oeordID,oeoriSub)) q:oeoriSub=""
            d ..getPatOrderBH(episodeID, patIndex, oeordID, oeoriSub, sheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns, currentSheetSetting, isCurrentSheet, .orderObject, .ordersData, .labData,colorsSetting)
        }
        ;;;q:..filterSearch(isCurrentSheet,sheetCode,orderObject) 0
        s ordCatDr="" 
        for {
             s ordCatDr=$O(^OEORDi(0,"StatStDtTm1",oeordID,ordCatDr)) q:ordCatDr=""         
             s stDate="" 
             for {
                 s stDate=$O(^OEORDi(0,"StatStDtTm1",oeordID,ordCatDr,stopSateDr,stDate)) q:stDate=""
                 s stTime="" 
                    for {
                      s stTime=$O(^OEORDi(0,"StatStDtTm1",oeordID,ordCatDr,stopSateDr,stDate,stTime)) q:stTime=""
                      s oeoriSub=0 
                      for {  
                        s oeoriSub=$O(^OEORDi(0,"StatStDtTm1",oeordID,ordCatDr,stopSateDr,stDate,stTime,oeoriSub)) q:oeoriSub=""
                        s seeOrdType=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",7)
                        continue:seeOrdType="U"
                        d ..getPatOrderBH(episodeID, patIndex, oeordID, oeoriSub, sheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns, currentSheetSetting, isCurrentSheet, .orderObject, .ordersData, .labData,colorsSetting)
                    }
                }
            }
        }
    }
    if ((excutedOrderFlag="true")!(excutedOrderFlag="all")) {
        ;;;q:..filterSearch(isCurrentSheet,sheetCode,orderObject) 0
        s startDate=queryArgument.startDateGet()
        s endDate=queryArgument.endDateGet()
        s startTime=queryArgument.startTimeGet()
        s endTime=queryArgument.endTimeGet()
        s createOrderFlag=queryArgument.createOrderFlagGet()
        s oeoriSub=0
        for
        {
            s oeoriSub=$o(^OEORD(oeordID,"I",oeoriSub))
            q:oeoriSub=""
            s seeOrdType=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",7)
            continue:seeOrdType="U"
            // 过滤子医嘱
            s ordSeqID=$p($g(^OEORD(oeordID,"I",oeoriSub,11)),"^",39)
            continue:ordSeqID'=""
            // 处理日期时间
            
            i (createOrderFlag="false") {
                // 获取处理医嘱日期时间
                s seeDate=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",5)
                s seeTime=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",6)
                s stopSeeDate=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",2)
                s stopSeeTime=$p($g(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",3)
                // 如果为停止已处理医嘱，则按停止处理时间查询
                i stopSeeDate'="" {
                    s seeDate=stopSeeDate
                    s seeTime=stopSeeTime
                }
                continue:(seeDate<startDate)||(seeDate>endDate)
                continue:(seeDate=startDate)&&(seeTime<startTime)
                continue:(seeDate=endDate)&&(seeTime>endTime)
            }
            d ..getPatOrderBH(episodeID, patIndex, oeordID, oeoriSub, sheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns, currentSheetSetting, isCurrentSheet, .orderObject, .ordersData, .labData,colorsSetting)
        }
    } 
    q 0
}

/// Description:    获取单条变化医嘱单医嘱数据
/// Input:          episodeID：当前患者就诊号，oeordID：医嘱ID
///                 oeoriSub：医嘱ID，sheetCode：单据Code(BHYZD)
///                 queryArgument：查询参数对象，ifDeliveryRoom：当前是否是产房(1:是产房、0:不是产房)
///                 admVisitStatus：患者状态，columns：需处理的列数组
///                 isCurrentSheet：当前单据是否为前端选中单据(1:是、0:不是)，orderObject：记录其他单据是否有医嘱的对象
///                 ordersData：前端选中单据医嘱数据，labData：记录同处置状态、同标本号合管医嘱      
/// Return:       
/// Other:
ClassMethod getPatOrderBH(episodeID, patIndex, oeordID, oeoriSub, sheetCode, queryArgument As OrderParam, ifDeliveryRoom, admVisitStatus, columns As %ListOfDataTypes, currentSheetSetting As %ArrayOfDataTypes, isCurrentSheet, orderObject As %ArrayOfDataTypes, ordersData, labData, colorsSetting As %ListOfDataTypes)
{
    n (episodeID, patIndex, oeordID, oeoriSub, sheetCode, queryArgument, ifDeliveryRoom, admVisitStatus, columns, currentSheetSetting, isCurrentSheet, orderObject, ordersData, labData, colorsSetting,%session)
    s seeType=$P($G(^OEORD(oeordID,"I",oeoriSub,"NUR")),"^",7)
    s ordSeqID=$p($g(^OEORD(oeordID,"I",oeoriSub,11)),"^",39)
    q:ordSeqID'=""
    s ordStatID=$p($G(^OEORD(oeordID,"I",oeoriSub,1)),"^",13) 
    q:ordStatID=""  
    
    // 医嘱开立日期时间
    s createDate=$p($g(^OEORD(oeordID,"I",oeoriSub,3)),"^",7)
    s createTime=$p($g(^OEORD(oeordID,"I",oeoriSub,1)),"^",17)
    //停止医嘱变化医嘱单按医嘱停止日期查询
    s stopDate=$p($g(^OEORD(oeordID,"I",oeoriSub,3)),"^",34)
    s stopTime=$p($g(^OEORD(oeordID,"I",oeoriSub,2)),"^",15)
    // 没停止日期时,取预停日期
    s:stopDate="" stopDate=$p($g(^OEORD(oeordID,"I",oeoriSub,9)),"^",9)
    s:stopTime="" stopTime=$p($g(^OEORD(oeordID,"I",oeoriSub,9)),"^",10)
    s startCreateDate=+$h
    s endCreateDate=+$h
    s startCreateTime=0 
    s endCreateTime=86399
    s quitFlag=0
    s stopSateDr=$O(^OEC("OSTAT",0,"Code","D",""))
    if (ordStatID=stopSateDr){
        i (stopDate<startCreateDate)||(stopDate>endCreateDate) s quitFlag=1
        i (stopDate=startCreateDate)&&(stopTime<startCreateTime) s quitFlag=1
        i (stopDate=endCreateDate)&&(stopTime>endCreateTime) s quitFlag=1
    }else{
        //按开医嘱时间查询
        i (createDate<startCreateDate)||(createDate>endCreateDate) s quitFlag=1
        i (createDate=startCreateDate)&&(createTime<startCreateTime) s quitFlag=1
        i (createDate=endCreateDate)&&(createTime>endCreateTime) s quitFlag=1
    }
    q:$g(quitFlag)=1 0
    s newDisconFlag=queryArgument.newDisconFlagGet()
    s newCreateFlag=queryArgument.newCreateFlagGet()    
    s curDate=+$h
    s quitFlag=0
    i (newDisconFlag="true")&&(newCreateFlag="false") {
        // 今日新停，过滤医嘱状态不是停止的
        i (ordStatID'=stopSateDr) s quitFlag=1
        // 过滤停止日期不是当天的  
        i (stopDate'=curDate) s quitFlag=1
    }elseif (newDisconFlag="false")&&(newCreateFlag="true"){
        // 今日新开，过滤开医嘱日期不是当天的
        i (createDate'=curDate) s quitFlag=1
    }elseif (newDisconFlag="true")&&(newCreateFlag="true"){
        // 今日新开和今日新开
        i ((ordStatID=stopSateDr)&&(stopDate'=curDate))||((ordStatID'=stopSateDr)&&(createDate'=curDate)) s quitFlag=1
    }
    q:$g(quitFlag)=1 0
    
    // 过滤绑定需屏蔽医嘱
    s MethodParam=$g(^oddCOM("Nur.Interface.OutSide.Order","m","IsBindShieldOrder",60))
    i $lg($lg(MethodParam,1),1)="sheetCode" {
        s isBindShieldOrder=##Class(Nur.Interface.OutSide.Order).IsBindShieldOrder(sheetCode,oeordID_"||"_oeoriSub)
    }else {
         s isBindShieldOrder=##Class(Nur.Interface.OutSide.Order).IsBindShieldOrder(oeordID_"||"_oeoriSub)
    }
    q:isBindShieldOrder=1 0
    
    s excutedOrderFlag=queryArgument.excutedOrderFlagGet()
    if (excutedOrderFlag'="true") {
        s filterAlreadySee="N"
    }
    if ((excutedOrderFlag="true")!(excutedOrderFlag="all")) {
        s filterAlreadySee="Y"
    }
    s wardID=queryArgument.wardIDGet()
    s ctcptType=queryArgument.ctcptTypeGet()
    s locID=queryArgument.locIDGet()
    s locType=queryArgument.locTypeGet()
    s curWardLinkDocFlag=..OrdWardLinkDoc(wardID, ctcptType, "", oeordID_"||"_oeoriSub)
    s curLocLinkDocFlag=..OrdLocLinkWard(locID, ctcptType, oeordID_"||"_oeoriSub,currentSheetSetting.GetAt("filterPreOrd"))
    //s sheetOnlyShowCurRecLocOrd=currentSheetSetting.GetAt("sheetOnlyShowCurRecLocOrd") //仅显示接收科室为本科室医嘱
    //s sheetShowAnaestheAllStageOrd=currentSheetSetting.GetAt("sheetShowAnaestheAllStageOrd") //显示麻醉师所有医嘱阶段医嘱
    //接收科室
    //s recLoc=$p($g(^OEORD(oeordID,"I",oeoriSub,3)),"^",6)
    //q:(sheetOnlyShowCurRecLocOrd="Y")&&(recLoc'=locID)
    //麻醉师医嘱标识
    s AnaesthOrdFlag=..isAnaestheOrd(oeordID_"||"_oeoriSub)
    //下医嘱科室
    s ordDep=$p($g(^OEORD(oeordID,"I",oeoriSub,7)),"^",2)
    s ordLocType=""
    i ordDep'="" s ordLocType=$p(^CTLOC(ordDep),"^",13)
    // 医嘱是否为病区关联科室申请的会诊医嘱
    s ifConsultOrd=##class(Nur.IP.DrugAudit).IfConsultOrd(locID, oeordID, oeoriSub)
    // 获取医嘱阶段
    s stage=$p($g(^OEORD(oeordID,"I",oeoriSub,"DHC")),"^",8)
    if (ifDeliveryRoom=0) {
        // 过滤非本科本病区下的医护人员医嘱
        if (locType="OP") {
            q:(wardID'="")&&(curWardLinkDocFlag'="Y")&&(admVisitStatus'="P")&&(ifConsultOrd="N")&(stage'="SZ")&(stage'="SQ") 0 //&&(stage'="ALL")
        }else{
            q:(curLocLinkDocFlag'="Y")&&(admVisitStatus'="P")&&(ifConsultOrd="N") 0 //&&(stage'="ALL")
        }
    }else{
        // 如果当前病区为产房，则过滤掉非本科室医生所下的非产中医嘱
        q:(curLocLinkDocFlag'="Y")&&(stage'="CZ") 0 //&&(stage'="ALL")
    }
    // 获取医嘱处置状态(NeedToDeal:需处理医嘱，NeedToStop:需处理停止，AlreadyDeal:已处理，AlreadyStop:已处理停止)
    s disposeStatCode=##class(Nur.NIS.Service.Base.Order).GetOrderDisposeStatCode(oeordID, oeoriSub)
    q:disposeStatCode="" 0
    q:((disposeStatCode="NeedToDeal")!(disposeStatCode="NeedToStop"))&&(filterAlreadySee="Y") 0
    q:((disposeStatCode="AlreadyDeal")!(disposeStatCode="AlreadyStop"))&&((filterAlreadySee="N")) 0
    q:((disposeStatCode="SpecmentReject")!(disposeStatCode="RefuseDispDrug"))&&((filterAlreadySee="N")) 0  //安贞新加医嘱状态处理
    // 获取用于过滤的医嘱信息
    s filterInfo=..InitFilterInfo(oeordID, oeoriSub, "")
    d filterInfo.SetAt(disposeStatCode, "disposeStatCode")
    d filterInfo.SetAt(AnaesthOrdFlag,"AnaesthOrdFlag")
    d filterInfo.SetAt(locID,"locID")
    // 过滤医嘱
    s filterFlag=..FilterOrder(oeordID, oeoriSub, "", filterInfo, queryArgument, currentSheetSetting)
    q:filterFlag=0 0
    // 当前单据不是需处理,保存有数据标记后退出
    i (isCurrentSheet=0) {
        //d orderObject.SetAt("true","BGYZD") 
        d orderObject.SetAt("true",sheetCode) 
        q 0
    }
    // 获取主医嘱数据
    s orderInfo=..InitOrderInfo(oeordID,oeoriSub,"N",columns,colorsSetting,currentSheetSetting) 
    d orderInfo.SetAt(disposeStatCode,"disposeStatCode")
    d orderInfo.SetAt(locID,"locID")                    
    d orderInfo.SetAt(##class(%ListOfDataTypes).%New(),"childs")                    
    //查询子医嘱
    s child=0  
    f 
    {
        s child=$O(^OEORDi(0,"OEORI",oeordID,oeordID_"||"_oeoriSub,child))
        q:child=""
        //过滤子医嘱
        s childDisposeStatCode=##class(Nur.NIS.Service.Base.Order).GetOrderDisposeStatCode(oeordID, child)
        s childFilterInfo=..InitFilterInfo(oeordID, child, "")
        d childFilterInfo.SetAt(childDisposeStatCode,"disposeStatCode")
        d childFilterInfo.SetAt(locID,"locID")
        s childFilterFlag=..FilterOrder(oeordID, child, "", childFilterInfo, queryArgument, currentSheetSetting)
        continue:childFilterFlag=0
        // 获取子主医嘱数据
        s childOrderInfo=..InitOrderInfo(oeordID,child,"Y",columns,colorsSetting,currentSheetSetting)
        // 将子医嘱数据插入到主医嘱的childs属性上
        d orderInfo.GetAt("childs").Insert(childOrderInfo)
    }
    // 按照标本号及处置状态合并医嘱
    s labNo=orderInfo.GetAt("labNo")
    i (labNo'="") {
        s mergeSameLabNoFlag=..MergeSameLabNo(labNo, disposeStatCode, orderInfo, .labData,queryArgument,columns,currentSheetSetting,"",colorsSetting)
        //合管并退出
        q:mergeSameLabNoFlag=1 0
    }
    q:('queryArgument.PageFilter()) 0 ;;;PDA分页
    // 日期时间节点
    s sortDateTime=createDate*86400+createTime
    // 医嘱ID节点
    s sortID=oeordID_"||"_oeoriSub
    s arcimSerialNo=..getArcimSerialNo(currentSheetSetting,orderInfo.GetAt("ID"))
    s ordersData(patIndex,arcimSerialNo_sortDateTime,oeordID,oeoriSub)=orderInfo
    q 0
}

/// Description:    获取非需处理、非变化医嘱单及非当前单据外的其他单据的Code和护士执行筛选条件
/// Input:          hospID：医院Id wardID:病区ID currentSheetCode：当前单据code
/// Return:       
/// Other:          w ##class(Nur.JSON).Encode(##class(Nur.MNISV3.Service.QueryOrder).GetColorsSetting
ClassMethod GetColorsSetting(hospID, wardID, currentSheetCode, usePage = "NurE") As %ListOfDataTypes
{
    n (hospID,wardID,currentSheetCode,usePage,%session)
    s colorsSetting=##class(%ListOfDataTypes).%New()
    s EGHospID=##class(web.DHCBL.BDP.BDPMappingHOSP).GetDefHospIdByTableName("Nur_IP_ExecuteColorSet",hospID,"")
    s rowId=""
    for {
        s rowId=$o(^CF.NUR.NIS.ExecuteColorSetI("ECSHospDRIndex",EGHospID,rowId)) q:rowId=""
        s data=$g(^CF.NUR.NIS.ExecuteColorSetD(rowId))
        continue:data=""
        s ECSName=$lg(data,2)
        s ECSExpress=$lg(data,3)
        s ECSBackgroundColor=$lg(data,4)
        s ECSExecuteSheet=$lg(data,5)
        if (ECSExecuteSheet'="")&&(currentSheetCode'=""){
            s findSheetFlag=0
            for i=1:1:$l(ECSExecuteSheet,"^"){
                s sheetId=$p(ECSExecuteSheet,"^",i)
                continue:sheetId=""
                s sheetCode=$lg($g(^CF.NUR.NIS.NurseSheetSetD(sheetId)),2)
                if (currentSheetCode=sheetCode) s findSheetFlag=1 q
            }
            continue:findSheetFlag=0
        }
        s ECSValidLocs=$lg(data,6)
        continue:(ECSValidLocs'="")&&(("^"_ECSValidLocs_"^")'[("^"_wardID_"^"))
        s ECSInValidLocs=$lg(data,7)
        continue:(ECSInValidLocs'="")&&(("^"_ECSInValidLocs_"^")[("^"_wardID_"^"))
        s ECSActive=$lg(data,8)
        continue:ECSActive'="Y"
        s ECSExecutePage=$lg(data,10)
        continue:(ECSExecutePage'="")&&(("^"_ECSExecutePage_"^")'[("^"_usePage_"^"))
        s colorSetting=##class(%ArrayOfDataTypes).%New()
        d colorSetting.SetAt(ECSName,"name")
        d colorSetting.SetAt(ECSExpress,"express")
        d colorSetting.SetAt(ECSBackgroundColor,"backgroundColor")
        d colorsSetting.Insert(colorSetting)
    }
    q colorsSetting
}

/// Description:    获取医嘱背景色
/// Input:          
/// Return:       
/// Other:          w ##class(Nur.JSON).Encode(##class(Nur.MNISV3.Service.QueryOrder).GetBackgroundColor
ClassMethod GetBackgroundColor(oeordID, oeoriSub, subOrder, colorsSetting)
{
    s ordBackgroundColor=""
    s parameter=oeordID_"||"_oeoriSub
    s:subOrder'="" parameter=parameter_"||"_subOrder
    for i=1:1:colorsSetting.Count()
    {
        s colorSetting=colorsSetting.GetAt(i)
        s backgroundColor=colorSetting.GetAt("backgroundColor")
        s express=colorSetting.GetAt("express")
        s className=$p(express,":",1)
        s methodName=$p(express,":",2)
        s colorRet=""
        i (className'="")&&(methodName'="") {
            if (##class(websys.Conversions).IsValidMethodName(className,methodName)) {
                s x="(i,o) s o=##class("_className_")."_methodName_"("""_parameter_""")"
                x (x,"",.colorRet)
            }
        }
        if (colorRet'=""){
            s ordBackgroundColor=backgroundColor
        }
        q:ordBackgroundColor'=""
    }
    q ordBackgroundColor
}

/// w ##class(Nur.MNISV3.Service.QueryOrder).GetAttArcim("21||1||299","")
ClassMethod GetAttArcim(oeoreIdStr, wardID)
{
    n (oeoreIdStr,wardID,%session)
    s rtnJson=##class(%ListOfDataTypes).%New()
    for k=1:1:$l(oeoreIdStr,"^") {
        s oeoreId=$p(oeoreIdStr,"^",k)
        continue:oeoreId=""
        d rtnJson.Insert(..initAttArimByExec(oeoreId,wardID))
        /*s ret=""
        s json=##class(%ListOfDataTypes).%New()
        s arcimDr=$p(^OEORD(+oeoreId,"I",$p(oeoreId,"||",2),1),"^",2)
        s arcimDesc=$p($g(^ARCIM(+arcimDr,$p(arcimDr,"||",2),1)),"^",2)
        d json.Insert(##class(websys.Translation).Get("Nur.NIS.Service.OrderExcute.QueryOrder","执行记录")_"("_oeoreId_"):")
        d json.Insert(##class(User.ARCItmMast).GetTranByDesc("ARCIMDesc",arcimDesc)_" "_##class(Nur.NIS.Service.OrderExcute.OrderInfo).GetPrice(oeoreId)_priceUnit)
        s EpisodeID =$p($g(^OEORD(+oeoreId)),"^",1)
        d json.Insert(##class(websys.Translation).Get("Nur.NIS.Service.OrderExcute.QueryOrder","绑定费用")_"：")
        s attOrders=##class(Nur.NIS.Service.Base.Order).GetAttachOrder(oeoreId, 10, 2 , 2 ,1) //,1,wardID
        i attOrders.Count()>0 d json.Insert(##class(websys.Translation).Get("Nur.NIS.Service.OrderExcute.QueryOrder","首次")_"：")
        f i=1:1:attOrders.Count() {
            s itm=attOrders.GetAt(i)
            s arcimDesc=itm.GetAt("ArcimDesc")
            s arcimDr=itm.GetAt("ArcimId")
            s retPrice=##Class(web.DHCDocOrderEntry).GetOrderPrice("","",arcimDr,+$h,"","","","","","","^^"_EpisodeID) ;##class(web.DHCDocOrderEntry).GetOrderPrice("", "", arcimDr, +$h, "", "", "", "")
            s retPrice=$fn($P(retPrice,"^",1),"",3)_priceUnit
            i ret="" s ret=arcimDesc_"("_arcimDr_")  "_retPrice
            e  s ret=ret_$c(10,13)_arcimDesc_"("_arcimDr_")  "_retPrice
            d json.Insert(arcimDesc_"  "_retPrice)
        }
        s attOrders=##class(Nur.NIS.Service.Base.Order).GetAttachOrder(oeoreId, 11, 2 , 2 ,1) //,1,wardID
        i attOrders.Count()>0 d json.Insert(##class(websys.Translation).Get("Nur.NIS.Service.OrderExcute.QueryOrder","接瓶")_"：")
        f i=1:1:attOrders.Count() {
            s itm=attOrders.GetAt(i)
            s arcimDesc=itm.GetAt("ArcimDesc")
            s arcimDr=itm.GetAt("ArcimId")
            s retPrice=##Class(web.DHCDocOrderEntry).GetOrderPrice("","",arcimDr,+$h,"","","","","","","^^"_EpisodeID)
            s retPrice=$fn($P(retPrice,"^",1),"",3)_priceUnit
            i ret="" s ret=arcimDesc_"("_arcimDr_")  "_retPrice
            e  s ret=ret_$c(10,13)_arcimDesc_"("_arcimDr_")  "_retPrice
            d json.Insert(arcimDesc_"  "_retPrice)
        }
        s ArcimRowId = $p($g(^OEORD(+oeoreId,"I",$p(oeoreId,"||",2),1)),"^",2) /// 医嘱项ID
        s InstrRowId = $p($g(^OEORD(+oeoreId,"I",$p(oeoreId,"||",2),2)),"^",7)
        s autoAtts=##Class(DHCDoc.DHCDocConfig.InstrArcim).GetArcimWardInfo(EpisodeID,ArcimRowId,InstrRowId,2,"") //wardID
        s len=$L(autoAtts,$C(2))
        d json.Insert(##class(websys.Translation).Get("Nur.NIS.Service.OrderExcute.QueryOrder","自动")_":")
        s flag=0
        f i=1:1:len {
            s itm=$p(autoAtts,$C(2),i)
            continue:itm=""
            s arcimDr=$p(itm,"^",1)
            continue:arcimDr=""
            s byHand=$p(autoAtts,"^",8)
            q:byHand=2
            s arcimDesc=$P($G(^ARCIM(+arcimDr,$p(arcimDr,"||",2),1)),"^",2)
            s retPrice=##Class(web.DHCDocOrderEntry).GetOrderPrice("","",arcimDr,+$h,"","","","","","","^^"_EpisodeID)
            s retPrice=$fn($P(retPrice,"^",1),"",3)_priceUnit
            i ret="" s ret=arcimDesc_"("_arcimDr_")  "_retPrice
            e  s ret=ret_$c(10,13)_arcimDesc_"("_arcimDr_")  "_retPrice
            d json.Insert(arcimDesc_"  "_retPrice)
            s flag=1
        }
        i flag=0 d json.RemoveAt(json.Count())
        i ret="" {
            s ret=##class(websys.Translation).Get("Nur.NIS.Service.OrderExcute.QueryOrder","无绑定费用")
            d json.Insert(##class(websys.Translation).Get("Nur.NIS.Service.OrderExcute.QueryOrder","无绑定费用"))
        }
        d rtnJson.Insert(json)*/
        
        s child=0  F {
            s child=$O(^OEORDi(0,"OEORI",+oeoreId,$p(oeoreId,"||",1,2),child)) Q:child=""
            s childsub=0
            for {
                s childsub=$o(^OEORDi(0,"OEORE",oeoreId,+oeoreId,child,childsub)) q:childsub=""
                d rtnJson.Insert(..initAttArimByExec(+oeoreId_"||"_child_"||"_childsub,wardID))
            }
        }   
    }   
    q rtnJson
}

ClassMethod initAttArimByExec(oeoreId, wardID)
{
    s priceUnit=##class(websys.Translation).Get("Nur.NIS.Service.OrderExcute.QueryOrder","元")
    s ret=""
    s json=##class(%ListOfDataTypes).%New()
    s arcimDr=$p(^OEORD(+oeoreId,"I",$p(oeoreId,"||",2),1),"^",2)
    s arcimDesc=$p($g(^ARCIM(+arcimDr,$p(arcimDr,"||",2),1)),"^",2)
    d json.Insert(##class(websys.Translation).Get("Nur.NIS.Service.OrderExcute.QueryOrder","执行记录")_"("_oeoreId_"):")
    d json.Insert(##class(User.ARCItmMast).GetTranByDesc("ARCIMDesc",arcimDesc)_" "_##class(Nur.NIS.Service.OrderExcute.OrderInfo).GetPrice(oeoreId)_priceUnit)
    s EpisodeID =$p($g(^OEORD(+oeoreId)),"^",1)
    d json.Insert(##class(websys.Translation).Get("Nur.NIS.Service.OrderExcute.QueryOrder","绑定费用")_"：")
    s attOrders=##class(Nur.NIS.Service.Base.Order).GetAttachOrder(oeoreId, 10, 2 , 2 ,1) //,1,wardID
    i attOrders.Count()>0 d json.Insert(##class(websys.Translation).Get("Nur.NIS.Service.OrderExcute.QueryOrder","首次")_"：")
    f i=1:1:attOrders.Count() {
        s itm=attOrders.GetAt(i)
        s arcimDesc=itm.GetAt("ArcimDesc")
        s arcimDr=itm.GetAt("ArcimId")
        s retPrice=##Class(web.DHCDocOrderEntry).GetOrderPrice("","",arcimDr,+$h,"","","","","","","^^"_EpisodeID) ;##class(web.DHCDocOrderEntry).GetOrderPrice("", "", arcimDr, +$h, "", "", "", "")
        s retPrice=$fn($P(retPrice,"^",1),"",3)_priceUnit
        i ret="" s ret=arcimDesc_"("_arcimDr_")  "_retPrice
        e  s ret=ret_$c(10,13)_arcimDesc_"("_arcimDr_")  "_retPrice
        d json.Insert(arcimDesc_"  "_retPrice)
    }
    s attOrders=##class(Nur.NIS.Service.Base.Order).GetAttachOrder(oeoreId, 11, 2 , 2 ,1) //,1,wardID
    i attOrders.Count()>0 d json.Insert(##class(websys.Translation).Get("Nur.NIS.Service.OrderExcute.QueryOrder","接瓶")_"：")
    f i=1:1:attOrders.Count() {
        s itm=attOrders.GetAt(i)
        s arcimDesc=itm.GetAt("ArcimDesc")
        s arcimDr=itm.GetAt("ArcimId")
        s retPrice=##Class(web.DHCDocOrderEntry).GetOrderPrice("","",arcimDr,+$h,"","","","","","","^^"_EpisodeID)
        s retPrice=$fn($P(retPrice,"^",1),"",3)_priceUnit
        i ret="" s ret=arcimDesc_"("_arcimDr_")  "_retPrice
        e  s ret=ret_$c(10,13)_arcimDesc_"("_arcimDr_")  "_retPrice
        d json.Insert(arcimDesc_"  "_retPrice)
    }
    s ArcimRowId = $p($g(^OEORD(+oeoreId,"I",$p(oeoreId,"||",2),1)),"^",2) /// 医嘱项ID
    s InstrRowId = $p($g(^OEORD(+oeoreId,"I",$p(oeoreId,"||",2),2)),"^",7)
    s autoAtts=##Class(DHCDoc.DHCDocConfig.InstrArcim).GetArcimWardInfo(EpisodeID,ArcimRowId,InstrRowId,2,"") //wardID
    s len=$L(autoAtts,$C(2))
    d json.Insert(##class(websys.Translation).Get("Nur.NIS.Service.OrderExcute.QueryOrder","自动")_":")
    s flag=0
    f i=1:1:len {
        s itm=$p(autoAtts,$C(2),i)
        continue:itm=""
        s arcimDr=$p(itm,"^",1)
        continue:arcimDr=""
        s byHand=$p(itm,"^",8)
        continue:byHand=2
        s arcimDesc=$P($G(^ARCIM(+arcimDr,$p(arcimDr,"||",2),1)),"^",2)
        s retPrice=##Class(web.DHCDocOrderEntry).GetOrderPrice("","",arcimDr,+$h,"","","","","","","^^"_EpisodeID)
        s retPrice=$fn($P(retPrice,"^",1),"",3)_priceUnit
        i ret="" s ret=arcimDesc_"("_arcimDr_")  "_retPrice
        e  s ret=ret_$c(10,13)_arcimDesc_"("_arcimDr_")  "_retPrice
        d json.Insert(arcimDesc_"  "_retPrice)
        s flag=1
    }
    i flag=0 d json.RemoveAt(json.Count())
    i ret="" {
        s ret=##class(websys.Translation).Get("Nur.NIS.Service.OrderExcute.QueryOrder","无绑定费用")
        d json.Insert(##class(websys.Translation).Get("Nur.NIS.Service.OrderExcute.QueryOrder","无绑定费用"))
    }
    q json
    //d rtnJson.Insert(json)
    //q rtnJson
}

ClassMethod GetOrdExecAddInfoList(oeoreId, currentSheetSetting As %ArrayOfDataTypes, ByRef orderExecInfo)
{
    n (oeoreId,currentSheetSetting,orderExecInfo,%session)
    s ordSeqID=$p($g(^OEORD(+oeoreId,"I",$p(oeoreId,"||",2),11)),"^",39)
    s ordAddInfoValueList=##class(%ListOfDataTypes).%New()
    s ordAddInfoList=currentSheetSetting.GetAt("ordAddInfoList")
    for i=1:1:ordAddInfoList.Count() {
        s ordAddInfo=ordAddInfoList.GetAt(i)
        s key=ordAddInfo.GetAt("itemCode")
        continue:key=""
        //过滤显示模式为医嘱模式的配置
        s itemShowMode=ordAddInfo.GetAt("itemShowMode")
        //continue:(itemShowMode="Ord")
        //子医嘱是否显示
        s subOrdShow=ordAddInfo.GetAt("itemSubOrdShow")
        continue:(subOrdShow="N")&&(ordSeqID'="")
        if (orderExecInfo.IsDefined(key)){
            s value=orderExecInfo.GetAt(key)
        }else{
            s value=##class(Nur.NIS.Service.Base.BedConfig).GetBasicDataByCode(2,key,oeoreId)
            if (value="") {
                s value=##class(Nur.NIS.Service.Base.BedConfig).GetBasicDataByCode(1,key,oeoreId)
            }
            s value=##class(ext.util.String).EvalJSON(value)
            d orderExecInfo.SetAt(value,key)
        }
        //continue:value=""
        s addValueInfo=##class(%ArrayOfDataTypes).%New()
        d addValueInfo.SetAt(key,"key")
        d addValueInfo.SetAt(value,"value")
        d addValueInfo.SetAt(ordAddInfo.GetAt("itemBackgroundColor"),"backgroundColor")
        d addValueInfo.SetAt(ordAddInfo.GetAt("itemFontColor"),"fontColor")
        d addValueInfo.SetAt(itemShowMode,"itemShowMode")
        d ordAddInfoValueList.Insert(addValueInfo)
    }
    d orderExecInfo.SetAt(ordAddInfoValueList,"ordAddInfoValueList")
}

ClassMethod GetOrdAddInfoList(oeoriId, subOrder, currentSheetSetting As %ArrayOfDataTypes, ByRef orderInfo)
{
    n (oeoriId,subOrder,currentSheetSetting,orderInfo,%session)
    s ordAddInfoValueList=##class(%ListOfDataTypes).%New()
    s ordAddInfoList=currentSheetSetting.GetAt("ordAddInfoList")
    for i=1:1:ordAddInfoList.Count() {
        s ordAddInfo=ordAddInfoList.GetAt(i)
        s key=ordAddInfo.GetAt("itemCode")
        continue:key=""
        //过滤显示模式为执行记录模式的配置
        s itemShowMode=ordAddInfo.GetAt("itemShowMode")
        //continue:(itemShowMode="OrdExec")
        //子医嘱是否显示
        s subOrdShow=ordAddInfo.GetAt("itemSubOrdShow")
        continue:(subOrdShow="N")&&(subOrder="Y")
        if (orderInfo.IsDefined(key)){
            s value=orderInfo.GetAt(key)
        }else{
            s value=##class(Nur.NIS.Service.Base.BedConfig).GetBasicDataByCode(1,key,oeoriId)
            //if (key="filteFlagExtend")&&('value) s value=##class(Nur.NIS.Service.Base.BedConfig).GetBasicDataByCode(2,key,oeoriId)
            s value=##class(ext.util.String).EvalJSON(value)
            d orderInfo.SetAt(value,key)
        }
        //continue:value=""
        s addValueInfo=##class(%ArrayOfDataTypes).%New()
        d addValueInfo.SetAt(key,"key")
        d addValueInfo.SetAt(value,"value")
        d addValueInfo.SetAt(ordAddInfo.GetAt("itemBackgroundColor"),"backgroundColor")
        d addValueInfo.SetAt(ordAddInfo.GetAt("itemFontColor"),"fontColor")
        d addValueInfo.SetAt(itemShowMode,"itemShowMode")
        d ordAddInfoValueList.Insert(addValueInfo)
    }
    d orderInfo.SetAt(ordAddInfoValueList,"ordAddInfoValueList")
}

/// Description:    获取单据类型
/// Input:          sheetCode：单据code，hospID：医院ID
/// Return:         "DefaultSee":"需关注","BGYZD":"变更医嘱","Other":"其它"
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).GetSheetTypeBySheetCode("DefaultSee","2")
ClassMethod GetSheetTypeBySheetCode(sheetCode, hospID)
{
    n (sheetCode, hospID, %session)
    s defHospID=##class(web.DHCBL.BDP.BDPMappingHOSP).GetDefHospIdByTableName("Nur_IP_ExecuteSheet",hospID,"")
    s rowID=$o(^CF.NUR.NIS.NurseSheetSetI("Code",defHospID," "_$zcvt(sheetCode,"U"),""))
    i (rowID'="") {
        s data=$g(^CF.NUR.NIS.NurseSheetSetD(rowID))
        s sheetType=$lg(data,44) //单据类型，若护士执行-单据类型为空，默认未"其它"类型
        if (sheetType="") s sheetType="Other"
        q sheetType
    }
    q "Other"
}

/// Description:    获取开医嘱人是否是麻醉师(医护人员-麻醉师)
/// Input:          oeoriId：医嘱ID
/// Return:         Y:是 其它:不是
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).isAnaestheOrd
ClassMethod isAnaestheOrd(oeoriId) As %String
{
    n (oeoriId)
    s oeordId=+oeoriId,oeoriSub=$p(oeoriId,"||",2)
    q:oeoriId="" "N"
    s EpisodeID=+^OEORD(oeordId)
    q:EpisodeID=0 "N"
    s userId=$P($G(^OEORD(oeordId,"I",oeoriSub,7)),"^",1)
    q:userId="" "N"
    s ctcpId=$P($g(^SSU("SSUSR",userId)),"^",14)
    q:ctcpId="" "N"
    s ctcptId=$P($g(^CTPCP(ctcpId,1)),"^",4) 
    q:ctcptId="" "N"
    s AnaestheFlag=$P($g(^CTPCP(ctcpId,2)),"^",19) 
    q AnaestheFlag
}

/// Creator:        songchao
/// CreatDate:      2017.12.27
/// Description:    判断科室是否是产房(护理扩展设置-产房)
/// Input：          
/// Return:         1:是 0:否
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).ifDeliveryRoom
ClassMethod ifDeliveryRoom(locId) As %String
{
    n (locId,%session)
    q:locId="" 0
    s hospitalID=$p(^CTLOC(locId),"^",22)
    s hospitalID=##class(web.DHCBL.BDP.BDPMappingHOSP).GetDefHospIdByTableName("Nur_IP_ExtendSet",hospitalID,"")
    s extentSetId=$o(^CF.NUR.NIS.ExtendSetI("ESCodeIndex",hospitalID," 0"," DELIVERYROOM",""))
    q:extentSetId="" 0
    q:$o(^CF.NUR.NIS.ExtendItemSetI("EISItemDrIndex",extentSetId," 0"," "_locId,""))'="" 1
    q 0
}

/// Creator:        songchunli
/// CreatDate:      2024.04.17
/// Description:    获取交班本班制
/// Input：          
/// Other:          w ##class(Nur.MNISV3.Service.QueryOrder).getShiftClassList(2,"","")
ClassMethod getShiftClassList(HospID, WardID, LocID)
{
    s ClassList=##class(%ListOfDataTypes).%New()
    s defHosp=##class(Nur.NIS.Common.Utils).GetHospitalID(##class(Nur.NIS.Common.ConstVal).#TABLEOBS,HospID)
    s rowID=""
    for{
        s rowID=$o(^CF.NUR.SHIFT.ShiftClassD(rowID)) q:rowID=""
        s IsDeleted=$lg(^CF.NUR.SHIFT.ShiftClassD(rowID),6)
        continue:IsDeleted=1
        s classHospID=$lg(^CF.NUR.SHIFT.ShiftClassD(rowID),9)
        continue:classHospID'=defHosp
        s ShiftWardID=$lg(^CF.NUR.SHIFT.ShiftClassD(rowID),10)
        s ShiftLocID=$lg(^CF.NUR.SHIFT.ShiftClassD(rowID),11)
        if (WardID="")&&(LocID=""){
            continue:ShiftWardID'=""
            continue:ShiftLocID'=""
        }
        continue:(WardID'="")&&(ShiftWardID'=WardID)
        continue:(LocID'="")&&(ShiftLocID'=LocID)
        s shiftClassName=$lg(^CF.NUR.SHIFT.ShiftClassD(rowID),5)
        s shiftClassName= ##class(Nur.SHIFT.Service.ShiftController).GetTransDesc("CF.NUR.SHIFT.ShiftBook","ShiftClassName","",shiftClassName)
        //获取班次
        s bookTimeList=##class(%ListOfDataTypes).%New()
        s bookTimeID=""
        for{
            s bookTimeID=$o(^CF.NUR.SHIFT.ShiftTimeI("class",rowID,bookTimeID)) q:bookTimeID=""
            s timeDelete=$lg(^CF.NUR.SHIFT.ShiftTimeD(bookTimeID),7)
            continue:timeDelete=1
            s shiftName=$lg(^CF.NUR.SHIFT.ShiftTimeD(bookTimeID),8)
            s shiftName= ##class(Nur.SHIFT.Service.ShiftController).GetTransDesc("CF.NUR.SHIFT.ShiftBook","ShiftName","",shiftName)
            s bookTimeObj=##class(%ArrayOfDataTypes).%New()
            d bookTimeObj.SetAt(bookTimeID,"shifTimetId")
            d bookTimeObj.SetAt(shiftName,"shiftTimeName")
            s ShiftStartSymbol=$lg(^CF.NUR.SHIFT.ShiftTimeD(bookTimeID),3)
            s shiftStartDate= ##class(websys.Conversions).DateLogicalToHtml(+$h+ShiftStartSymbol)
            s shiftStartTime=$lg(^CF.NUR.SHIFT.ShiftTimeD(bookTimeID),4)
            i shiftStartTime="" s shiftStartTime="00:00"
            s ShiftEndSymbol=$lg(^CF.NUR.SHIFT.ShiftTimeD(bookTimeID),5)
            s shiftEndDate= ##class(websys.Conversions).DateLogicalToHtml(+$h+ShiftEndSymbol)
            s shiftEndTime=$lg(^CF.NUR.SHIFT.ShiftTimeD(bookTimeID),6)
            i shiftEndTime="" s shiftEndTime="23:59"
            d bookTimeObj.SetAt(shiftStartDate,"shiftStartDate")
            d bookTimeObj.SetAt(shiftStartTime,"shiftStartTime")
            d bookTimeObj.SetAt(shiftEndDate,"shiftEndDate")
            d bookTimeObj.SetAt(shiftEndTime,"shiftEndTime")
            d bookTimeList.Insert(bookTimeObj)
        }
        continue:'bookTimeList.Count()
        s ClassObj=##class(%ArrayOfDataTypes).%New()
        d ClassObj.SetAt(shiftClassName,"shiftClassName")
        d ClassObj.SetAt(rowID,"shiftClassId")
        d ClassObj.SetAt(bookTimeList,"bookTimeList")
        d ClassList.Insert(ClassObj)
    }
    q ##class(Nur.JSON).Encode(ClassList)
    q ClassList
}

}
